Hello,
I want to bind my Custom property to IsEnabled property of DataRecord of xamDataGrd.
Is there any way to do this? Can I do it using Style or something?
Thanks & Regards,
Abdi
Hello Abdeali,
You can create a style for DataRecordPresenter in the resources of XamDataGrid and by using a Setter you can bind it’s IsEnabled property to your custom property:
<Style TargetType="{x:Type igWPF:DataRecordPresenter}"> <Setter Property="IsEnabled" Value="{Binding Source={StaticResource vm},Path=Enabled}"/></Style>
I have attached simple project where you can see this approach.
Please let me know if you require any further assistance regarding this matter.
Sincerely, ZhivkoEntry Level Software Developer
Thanks for the reply. I am very close to the solution as per your suggestion. The only issue is I am unable to bind my property (from a collection) in DataTrigger:
<Style TargetType="{x:Type igDP:DataRecordPresenter}"> <Setter Property="IsEnabled" Value="False"/> <Style.Triggers> <DataTrigger Binding="{Binding Record.DataItem.ReReversedTransactionID}" Value="{x:Null}" > <Setter Property="IsEnabled" Value="True"/> </DataTrigger>
</Style.Triggers>
</Style>
Here ReReversedTransactionID is the property i am trying to bind. The row should get enabled when value of this property is null. This style is under the xamDataGrid.Resources. This grid is bind with a DataSource and this property is present in this datasource.
Thanks,
You can try to specify the RelativeSource in the Binding that you are using and also change the expected value in the DataTrigger, for example:
<Style TargetType="{x:Type igWPF:DataRecordPresenter}"> <Setter Property="IsEnabled" Value="False"/> <Style.Triggers> <DataTrigger Binding="{Binding RelativeSource={RelativeSource Self}, Path=Record.DataItem.ReReversedTransactionID}" Value="null" > <Setter Property="IsEnabled" Value="True"/> </DataTrigger> </Style.Triggers></Style>
I am glad your solution is working now.
Please let me know if you have any more questions.
<DataTrigger Binding="{Binding RelativeSource={RelativeSource Self}, Path=Record.DataItem.ReverseTransactionID, Converter={StaticResource NumericToBoolConverterKey}}" Value="False" > <Setter Property="IsEnabled" Value="False"/> </DataTrigger>
Hi Zhivko,
In my case Converter did the job!
Thanks for your inputs :)
Thanks Zhivko for your suggestion.
It works perfectly fine in the sample application i created. But is not working where i want it to be!
The thing is that, in sample application i am directly using XamDataGrid. Under this i have all my resources, field layouts, etc...
Now in my real application i am using a CustomGrid which is being created by inheriting XamDataGrid. So it's my assumption that RelativeSource is something which is not proper in my case.
Any suggestion would be helpful.