Hello everyone!
I've faced a really strange problem with data-binding. The grid is bound to a DataView. I've declared some Field-s in the grid. And the field has the CellValuePresenterStyle property set in its settings.
Also, there is a textbox and a textblock, which are bound to a single (e.g. first) row of that DataView. The Text property of the textBox and the textBlock is bound to the field named 'Name'.
If a user edits text in the TextBox, the Name field is updated, so the textblock and the grid should be updated as well. But I only get the TextBlock updating as needed. The value of the needed cellin the grid is updated only after I scroll down the grid a lot and then return back, or after sorting, or after some other actions which apparently force the grid to update that cell.
But if i don't use the style to represent a cell's value, binding works fine.
Could someone please explain me what's wrong and how can I use styling and binding at the same time?
Here's some code:
<ig:XamDataGrid x:Name="xamDataGrid1" GroupByAreaLocation="AboveDataArea" DockPanel.Dock="Bottom" Background="#FFFFFFFF" >
......
<ig:XamDataGrid.FieldLayouts> <ig:FieldLayout Key="View1"> <ig:FieldLayout.Fields>
<ig:Field Name="NameField" Label="Name" > <ig:Field.Settings> <ig:FieldSettings AllowEdit="False" CellWidth="80" LabelWidth="80" CellValuePresenterStyle="{StaticResource NameFieldStyle}" CellMaxHeight="20"/> </ig:Field.Settings> </ig:Field>
</ig:FieldLayout.Fields>
</ig:XamDataGrid>
<Style x:Key="NameFieldStyle" TargetType="{x:Type ig:CellValuePresenter}"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type ig:CellValuePresenter}"> <TextBlock Text="{Binding Path=DataItem.Name}" VerticalAlignment="Center" Foreground="#FF151C55" Margin="5,0,0,0"/> </ControlTemplate> </Setter.Value> </Setter> </Style>
[Edit] One more thing: If I use DynamicResource instead of StaticResource - the style's not applied at all.
Text={TemplateBinding Value}