How do I enable/disable a button within a XamGrid? Below is an example xaml and I need to be able to enable/disable the buttonShipTo based on some business log.
<ig:XamGrid x:Name="gridPO" ColumnWidth="*" AutoGenerateColumns="False" CellEnteredEditMode="gridPO_CellEnteredEditMode" DeleteKeyAction="DeleteRowsOfSelectedCellsAndRows" RowEnteredEditMode="gridPO_RowEnteredEditMode" RowExitedEditMode="gridPO_RowExitedEditMode" Margin="0,20,5,5" CellExitingEditMode="gridPO_CellExitingEditMode" RowExitingEditMode="gridPO_RowExitingEditMode" Height="250">
<ig:UnboundColumn Key="unboundButton" IsFilterable="False" Width="55" > <ig:UnboundColumn.HeaderTemplate> <DataTemplate> <TextBlock Text="Ship To"/> </DataTemplate> </ig:UnboundColumn.HeaderTemplate> <ig:UnboundColumn.ItemTemplate> <DataTemplate> <Button x:Name="buttonShipTo" Content="Ship To" Click="buttonShipTo_Click" Height="20" Margin="0" Tag="{Binding ClubName}"/> </DataTemplate> </ig:UnboundColumn.ItemTemplate> </ig:UnboundColumn> </ig:XamGrid.Columns></ig:XamGrid>
Hi,
I'm guessing the logic to determine if the button is enabled/disabled is on a row level.
if that correct, then you just need a Binding with a ValueConverter attached to the IsEnabled property of the button. Where the ValueConverter performs the logic.
Or you can simply just add a property to the underlying data object that resolves to true or false based on your evaluation logic, and raise the PropretyChanged event off of your data object when it changes.
-SteveZ
The button is being added as ig:UnboundColumn so I can't really data bind it (this seems to be the behavior, is this correct?)
What is the best way to add a button to a xamGrid using xaml? When the button is added using below xaml code, the event SelectedRowsCollectionChanged is not triggered. How do I get the event triggered in such case? Could you advise? I need to execute some call (see below) first before the button click event.
private void gridPO_SelectedRowsCollectionChanged(object sender, SelectionCollectionChangedEventArgs<SelectedRowsCollection> e) { if (e.NewSelectedItems[0] != null) { // get the selected row to handle Child Window ShipToAddress try { selectedDetailLine = (PODetailLine)e.NewSelectedItems[0].Data; selectedDetailLineIndex = e.NewSelectedItems[0].Index; } catch (Exception ex) // detail line is clicked { //ChildWindow errorWin = new ErrorWindow(ex); //errorWin.Show(); MessageBox.Show("error in gridPO_SelectedRowsCollectionChanged: " + ex.Message); } } }
<ig:UnboundColumn Key="unboundButton" IsFilterable="False" Width="55" > <ig:UnboundColumn.HeaderTemplate> <DataTemplate> <TextBlock Text="Ship To"/> </DataTemplate> </ig:UnboundColumn.HeaderTemplate> <ig:UnboundColumn.ItemTemplate> <DataTemplate> <Button x:Name="buttonShipTo" Content="Ship To" Click="buttonShipTo_Click" Height="20" Margin="0" Tag="{Binding ClubName}"/> </DataTemplate> </ig:UnboundColumn.ItemTemplate> </ig:UnboundColumn>