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
455
Display Item in a cell using DataTempaltes
posted

Hi,

I have a use case where I need to wrap "Double" as "FractionaDouble" which will enable edit and view doubles as fractions.

I have a XamDataGrid for which certain columns are of the type FractionalDouble. When ever we change the value property of fractionalDouble (which implements INotifyPropertyChanged), the value displayed in the grid does not refresh, we realized that is due to fact that wpf is not refreshing Binding, as the object itself does not change, and the binding in CellValuePresenter is not targeting a specific property within myCustomObject which results in INotifyPropertyChanged to be ineffective.

I attempted to work around the situation by defining a dataTempalte for my customType.


    <DataTemplate DataType="{x:Type Data:FractionalDouble}">
      <StackPanel>
        <TextBlock Text="{Binding Path=AsString,Mode=OneWay Background="Green" Foreground="White"/>
      </StackPanel>
    </DataTemplate>

This did not have any effect as i realized that CellValuePresenter does not have a content presenter / even if it does have one its not referring to the DataTemplates defined in resources.

Second attempt i used override the a ControlTemplate of CellValuePresenter and add a contentPresenter to it. This worked how ever i have read couple of posts which discourage overriding controlTemplate of cellValuePresenter.

So before i start inventing the wheel, wanted to find out if

a) Is this possible using simple dataBinding + any XamDataGrid ./ CellValuePresenter featureto get the above case work

b) Any workaround to force CellValuePresenter to request toString again

c) Will virtualization and other features turn off if I override the template of CellValuePresenter.

d) Can i have a look at the ControlTemplate of CellValuePresenter so that i can make edit / override the required parts only.