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.
Hello Ramakrishna,
The answers to your questions (A - D):
A. I would need an example of your custom class that shows the limitation.
B. You would need to add a property to your object that returned the ToString and then raise ChangeNotificatios when any of the dependent properties chaged. You could then use an UnboundField and set the binding so that you bind to this property. Note this would likely solve the entire issue.
C. No, but I recommend changing the Template for the editor rather than for CellValuePresenter.
D. You may take a look at the default style file that is shipped with the product located: C:\Program Files\Infragistics\NetAdvantage 2010.3\WPF\DefaultStyles
Let me know if you have any question.
Thank you,Sam
Class Prototype:
public class FractionalDouble : ObservableObject {
public FractionalDouble(decimal value_., string format_,bool isFraction_){
IsFraction = isFraction_;
Value = value_;
}
private void FormatValue(decimal value_){
if(IsFraction)
{
StrValue = FractionalForamtter.Fromat(value_);
else{
StrValue = string.Format(val)
decimal _value;
public decimal Value {
get{
return _value;
set{
_value = value;
FormatValue(value);
NotifyChanged("Value");
NotifyChanged("StrValue");
private string _stringVal;
public string StrValue{
return _stringVal;
private set{
_stringVal = value;
$ 1b : We are using a data Table and the class is a value in DataTable & Columns are dynamically generated so we donot know upfront to set up binding in xaml / code behind.
$ 1d: thanks .. that helped.
$ 1c: Will try that out ..
Rama,
Rather than using a DataTemplate for your field, you can create UnboundFields dynamically and hide the Bound fields. To prevent editing, you could then set e.Cancel to true when the field entering edit mode is an UnboundField.
The following code accomplishes this:
private void xamDataGrid1_FieldLayoutInitialized(object sender, Infragistics.Windows.DataPresenter.Events.FieldLayoutInitializedEventArgs e){ Dictionary<Field, UnboundField> addingFields = new Dictionary<Field, UnboundField>(); foreach (Field f in e.FieldLayout.Fields) { if (f.DataType == typeof(FractionalDouble)) { UnboundField uf = new UnboundField(); uf.Name = f.Name + "Unbound"; uf.BindingPath = new PropertyPath("Fractional.StrValue"); uf.Label = f.Label.ToString(); addingFields.Add(f, uf); } } foreach (KeyValuePair<Field,UnboundField> kvp in addingFields) { e.FieldLayout.Fields.Insert(kvp.Key.Index, kvp.Value); kvp.Key.Visibility = Visibility.Collapsed; }} void xamDataGrid1_EditModeStarting(object sender, Infragistics.Windows.DataPresenter.Events.EditModeStartingEventArgs e){ e.Cancel = e.Cell is UnboundCell;}
I have also attached a sample that demonstrates this approach. Let me know if this will work for you.