How can I set my CheckBoxes inside of my ListBox to be disabled?
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; }
}
The Problem: I'm trying to disable my CheckBox's dynamically that are inside of my listbox. But when I disable the ListBox it also disables my vertical scroll bar. So now I'm thinking that I should access the CheckBoxes inside of the Listbox inside of my groupbox and then disable them one by one. How can I do this?
I tried this, but had no luck:
var children = LogicalTreeHelper.GetChildren(MyListBoxThing);
foreach(var item in children)
{
var c = item as CheckBox;
c.IsEnabled = false;
}
I want to say like:
loop through the listbox
if you find a check box
checkbox.isenabled = false
endif
end
Thanks in advance
Aucun commentaire:
Enregistrer un commentaire