Hi all,
I have a XamDataGrid and a Grid wich DataContext is Bound to the dataGrid´s ActiveDataItem. The Grid contains some controls with properties that depend on values of some fields.
For example, the Content of a Label should change depending on a value. I have code the Trigger:
<Label>
<Label.Triggers>
<Trigger Property="DataContext.Cells[MyField].Value" Value="True">
<Setter Property="Content" Value="MyText"/>
</Trigger>
</Label.Triggers>
</Label>
When compiling I get a DataContext.Cells[MyField] Property Not Found Error.
Any Idea?
Thanks in advance.
I see couple of more issues. I am sorry I missed them the first time.
Actually you are using a Trigger in the Triggers collection of the Label. The only type of triggers that you can use in an element's trigger collection is EventTrigger. So, in order for this to work you will have to create a style for the Label and use a data trigger instead.
Another issue is the binding. As you will be using a DataTrigger, you will also have to remove the DataContext from the binding expression as the DataTrigger will do that automatically.
Here is some sample code on how you can do this :
<DockPanel>
<igDP:XamDataGrid Name="xamDataGrid1" BindToSampleData="True"/>
<Grid DataContext="{Binding ActiveRecord, ElementName=xamDataGrid1}">
<Label Width="100">
<Label.Style>
<Style TargetType="Label">
<Style.Triggers>
<DataTrigger Binding="{Binding Cells[department].Value}" Value="Sales">
<Setter Property="Content" Value="My Text" />
</DataTrigger>
</Style.Triggers>
</Style>
</Label.Style>
</Grid>
</DockPanel>
It is bound to the ActiveRecord. Sorry for the mistake.
Hello,
If you are binding to the ActiveDataItem, then you will not have cells. The ActiveDataItem is the underlying object and you can bind to its properties directly. Probably you want to bind to the ActiveRecord which exposes cells?