I created a WPF Listview and is populated with instances of ProductCategory.
public class ProductCategory
{
public int Id { get; set; }
public string CategoryName { get; set; }
public DateTime CreatedDate { get; set; }
public DateTime LastUpdated { get; set; }
}
Next I create the list, populate it and assign it to the Listview control.
private List myProductList = new List();
// add some items to myProductList
// assign product list to ItemsSource property of a ListView
myListView.ItemsSource = myProductList;
In the XAML code, a button labelled "Edit" is added to each row. Each row represents an instance of ProductCategory:
<ListView x:Name="myListView" Height="352" HorizontalAlignment="Left" Margin="20,90,0,0" VerticalAlignment="Top" Width="1008">
<ListView.View>
<GridView>
<GridViewColumn Header="Category Name" DisplayMemberBinding="{Binding CategoryName}" Width="200"/>
<GridViewColumn Header="Created Date" DisplayMemberBinding="{Binding CreatedDate}" Width="200"/>
<GridViewColumn Header="Last Updated" DisplayMemberBinding="{Binding LastUpdated}" Width="200"/>
<GridViewColumn Header="Edit" Width="200">
<GridViewColumn.CellTemplate>
<DataTemplate>
<Button Content="Edit" Click="EditCategory" CommandParameter="{Binding}"/>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
</GridView>
</ListView.View>
</ListView>
When the user clicks the button, a dialog appears and the user can edit the data for an instance of ProductCategory. When the user closes the dialog, the user is returned to the Listview.
At this point I want to disable all the buttons in the Listview. How could I programmatically achieve this goal?
The buttons are not accessible in myListView.ItemsSource.