I have a ListView in a Windows Form that I bind a list of objects to on the creation of the form. What I would like to do is on a button click loop through the items that were created and change their IsEnabled property to false. I've tried two methods and neither were particularly successful. Can anyone help fix these up and/or suggest an alternate method?
My ListView XAML
<ListView Margin="6" Name="myListView" ItemsSource="{Binding Path=.}">
<ListView.ItemTemplate>
<DataTemplate>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="10"/>
<ColumnDefinition Width="350"/>
<ColumnDefinition Width="20"/>
<ColumnDefinition Width="350"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="30" />
<RowDefinition Height="30" />
<RowDefinition Height="30" />
</Grid.RowDefinitions>
<TextBlock Name="ItemNameTextBlock" Grid.Row="0" Grid.Column="1" Grid.ColumnSpan="4" VerticalAlignment="Center" Text="{Binding Path=ItemName}" />
<CheckBox Name="Action1CheckBox" Grid.Row="1" Grid.Column="1" Content="Action1" IsChecked="True" />
<CheckBox Name="Action2CheckBox" Grid.Row="1" Grid.Column="3" Content="Action2" IsChecked="True" />
<TextBox Height="23" Name="MyInputTextBox" Grid.Row="2" Grid.Column="1" Margin="2,0,2,0" VerticalAlignment="Top" Width="25" Text="{Binding Path=DataValue}" />
</Grid>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
Goal: On button press (of an unrelated button) disable the CheckBoxes and the TextBox
Attempt 1: This didn't work, the Items are the databound items and I cannot figure out a way to get to the controls themselves to do something like this. Is this even possible?
foreach (var item in ReleaseDeployProcessListView.Items)
{
((CheckBox)item.FindControl("Action1CheckBox")).IsEnabled = false;
}
Attempt 2: I added a public property "IsFormElementsEnabled" to the Form and on the button click set this value to false. But I couldn't figure out how/if/what i needed to do to bind that to the items. I tried IsEnabled="{Binding Path=IsFormElementsEnabled} (which doesn't work since it is bound to the objects and that is not party of those obects) and I tried IsEnabled="{Binding Path=this.IsFormElementsEnabled} (which doesn't seem to work either)