如何將我的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