如何将我的ListBox中的CheckBox设置为禁用?如何将我的ListBox中的CheckBox设置为禁用
XAML:
<GroupBox Header="A GroupBox" BorderThickness="2" Width="247" HorizontalAlignment="Left" VerticalAlignment="Top" Height="183" Margin="405,155,0,0">
<Grid>
<ListBox Name="MyListBoxThing" ItemsSource="{Binding MyItemsClassThing}" Height="151" Width="215" HorizontalAlignment="Left" VerticalAlignment="Top" ScrollViewer.VerticalScrollBarVisibility="Visible" ScrollViewer.HorizontalScrollBarVisibility="Auto" Margin="10,0,0,0">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<CheckBox IsChecked="{Binding IsSelected, Mode=TwoWay}" />
<TextBlock Text="{Binding Path=Name}"/>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</Grid>
</GroupBox>
Mainwindow.xaml.cs
public class MyItemsClassThing
{
public string Name { get; set; }
public bool IsSelected { get; set; }
}
的问题:我试图禁用我的CheckBox的动态是我的列表框的里面。但是,当我禁用列表框时,它也禁用了我的垂直滚动条。所以现在我想我应该访问我的GroupBox里面的列表框内的CheckBox,然后逐个禁用它们。我怎样才能做到这一点?
我想这一点,但没有运气:
var children = LogicalTreeHelper.GetChildren(MyListBoxThing);
foreach(var item in children)
{
var c = item as CheckBox;
c.IsEnabled = false;
}
我想说这样的:
loop through the listbox
if you find a check box
checkbox.isenabled = false
endif
end
在此先感谢
尝试绑定IsEnabled属性。 – Dexion