Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
660
Problems with binding to DataView while styling fields
posted

 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.

 

Parents
  • 8576
    Verified Answer
    Offline posted
    Hi -
     
    It sounds like the binding for the TextBlock's Text property in your style is not getting updated when the underlying value changes, which suggests that property change notifications are either not being fired (DataRowView should be doing this) or not being picked up for some reason. 
     
    Try changing the binding on the TextBlock's Text property to:
     
    Text={TemplateBinding Value}
     
    The XamDataGrid listens to all property change notifications and updates the CellValuePresenter's Value property when a change is detected.
     
    Joe
     
Reply Children