Hi Folks,
I have a Datagrid with a csutom columns that has a button as a content. The button is visible for all rows. What I would like to do is to make the button invisible and set IsEnabled to false if an underlying ViewModel for this row is of certain type. I do have a converter ready, but don't know how to connect it to the FieldSetting. Is my approach completely worong here? If so how to set thi up?
Thanks!
<igDP:UnboundField > <igDP:UnboundField.Settings> <igDP:FieldSettings> <igDP:FieldSettings.CellValuePresenterStyle> <Style TargetType="{x:Type igDP:CellValuePresenter}"> <Setter Property="Template"> <Setter.Value> <ControlTemplate> <Button Content="Command" Command="{Binding ShowPressureLossWindow}" Margin="3"/> </ControlTemplate> </Setter.Value> </Setter> </Style> </igDP:FieldSettings.CellValuePresenterStyle> </igDP:FieldSettings> </igDP:UnboundField.Settings> </igDP:UnboundField>
Hi Michal,
Thank you for posting to Infragistics Community!
I would suggest defining the field containing a button as a TemplateField instead, as this approach would be more suitable for such a scenario.
In order to bind a property of an element within the DisplayTemplate to another field of the underlying Data item, you could use the following: extended syntax:
<igWPF:TemplateField Name="FieldWithButton" BindingType="Unbound"> <igWPF:TemplateField.DisplayTemplate> <DataTemplate> <Button IsEnabled="{Binding Path=(igEditors:TemplateEditor.Editor).DataContext.DataItem.ShowButton, RelativeSource={RelativeSource Self}}" >Button</Button> </DataTemplate> </igWPF:TemplateField.DisplayTemplate> </igWPF:TemplateField>
If you like to bind to the Visibility property instead, a Converter can be used, for instance:
<Button Visibility="{Binding Path=(igEditors:TemplateEditor.Editor).DataContext.DataItem.ShowButton, RelativeSource={RelativeSource Self}, Converter={StaticResource myConverter}}" >Button</Button>
For your convenience, I am attaching a small sample demonstrating this suggestion. Please, check it out and let me know if you need any further assistance on the matter.
Best regards, Bozhidara Pachilova Associate Software Developer
6747.XDGTemplateField.zip
Hi Bozhidara, I implemented this and it indeed works. However, I lost the command functionality as this doesnt work anymore with the new solution. Can you help me with this as well?
Command="{Binding DataItem.ShowPressureLossWindowCommand}"
I am glad that you are having progress with implementing your requirement by following the TemplateField approach.
Regarding the Command binding, it is also a matter of configuring the correct path to bind the command. For example if it is a property on the ViewModel itself, which let’s say is the Window’s DataContext, it could be:
<igWPF:TemplateField.DisplayTemplate> <DataTemplate> <Button Command="{Binding Path=DataContext.Cmd, RelativeSource={RelativeSource AncestorType=Window, Mode=FindAncestor}}" CommandParameter="{Binding Path=(igEditors:TemplateEditor.Editor).DataContext.DataItem, RelativeSource={RelativeSource Self}}" >Execute command</Button> </DataTemplate> </igWPF:TemplateField.DisplayTemplate>
Please, keep in mind that this would depend on your specific application setup. Attached you will find another similar sample demonstrating such a button bound to a command.
Please, let me know if it helps.
Best regards,
Bozhidara Pachilova
Associate Software Developer
6761.XDGDisplayTemplateCmd.zip
Hi Bozhidara,
this worked. Thanks a lot for help!
<igDP:TemplateField Name="FieldWithButton" BindingType="Unbound"> <igDP:TemplateField.DisplayTemplate> <DataTemplate> <Button Content="Additional Pressure Drop" Command="{Binding Path=(igEditors:TemplateEditor.Editor).DataContext.DataItem.ShowPressureLossWindowCommand, RelativeSource={RelativeSource Self}}" IsEnabled="{Binding Path=(igEditors:TemplateEditor.Editor).DataContext.DataItem.ShowButton, RelativeSource={RelativeSource Self}}" /> </DataTemplate> </igDP:TemplateField.DisplayTemplate> </igDP:TemplateField>
I am glad that you find my suggestion helpful. Thank you for using Infragistics components!