I have a Data Grid and many buttons for commands on the selected item in the data grid.
These buttons will be hidden or disabled based on properties in the selected item in the grid.
For example: if the selected record IsNew, the button Cancel will be disabled.
What’s the best practice to implement a situation like this?
I may implement it in the SelectedItemChange manually like the follwoing:
void myGrid_selectedItemChanged(sender, args..)
{
cancelButton.IsEnabled = SelectedItem.IsNew ; // just an example
}
The problem with this approach is that, when the selected item is removed, this event will not be fired.
Or in XAML, bind a dependency property with the control:
<!--SelectedItemIsNew is a property in the form and binding it with IsEnabled... -->
<Button x:Name="cancelButton" IsEnabled="{Binding SelectedItemIsNew ...}"/>
The problem here, I must assign a value to the property to notify the bound control, or in other words what’s the code here to change the value of the property ?
Another option!
hey, i have the same case some time back, i always do that when ever i bind some data with grid or list in SL/WPF as it is easy and more understandable. why dont you try Binding coustom list to your code?? For examlple.. take and Filed like say String HyperLinkNaviagtion
when you get values fro service then befor assigning list to your grid, iterate on all of your items and assign HyperLinkNaviagtion some value like
and in Xaml, do the following
NavigateUri=”{Binding HyperLinkNaviagtion }”
It is don, you can control almost every thing like this =)
this might be not the best but in my case it is easiest and tension free too .