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}
Thank you for your reply.
The DataRowView does send notifications. I can see that, because other controls respond to that change.
And the XamDataGrid responds to the notification as well, but not before i deselect the record and scroll far away (or do whatever other action like that). I suppose it might has something to do with the fact that I'm using StaticResource, but with DynamicResource style is not applied at all.
I tried this:
Joe, I have one more probelm with this.
If the dataset is being changed by merging it with another dataset (of the same scheme of course) through the Merge() method, then the same story happens. The cells that should be changed are not updated, until I deselect the datarecord and do some scrolling back and forth. Although those cells update perfectly if changes to the dataset were made in another way, as I already said in my prev post.
Do you know what can cause this? Thanks
It's strange but it works perfectly with
{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Value}
Although, {TemplateBinding Value} is kind of the same, just different notation (as MSDN says)
Anyway, thanks for help!