Hi,
I want to write a fixed ControlTemplate for all unboundfields(So i can't write the full bindingPath in this controlTemplate ) which the cell value is a Type A object in my project. But i can't get the Type A object ,the value of ValueEditor is a string.
I'm using AlternateBinding to set the Type A object to this field on field's definition.
Binding alternateBinding = new Binding(); alternateBinding.Path = new PropertyPath(string.Format("Fields[{0}]", fieldEditor.Name));
Field field = new Field() { Name = fieldEditor.Name, Label = fieldEditor.Label, Column = startColumnIndex, BindingType = BindingType.UseAlternateBinding, AlternateBinding = alternateBinding}
My template:
<ControlTemplate x:Key="stringEditorTemplate" TargetType="{x:Type igEditors:ValueEditor}"> <Grid DataContext="{TemplateBinding Value}" Visibility="{Binding IsVisible,Converter={StaticResource BoolToVisibilityConverter}}"> <local:RMTextBlock Text="{Binding Text}" Style="{StaticResource StringEditorTemplateTextBlockStyle}"/> </Grid> </ControlTemplate>
editorStyle.Setters.Add(new Setter(ValueEditor.TemplateProperty, Application.Current.Resources["stringEditorTemplate"]));
field.Settings.EditorStyle = editorStyle;
------------------------------------------------------------------------------------------
If i'm using RelativeSource to find the value of CellValuePresenter is correct. But the output print binding errors while the data record is initializing.
<ControlTemplate x:Key="stringEditorTemplate" TargetType="{x:Type igEditors:ValueEditor}"> <Grid DataContext="{Binding Value,RelativeSource={RelativeSource AncestorType={x:Type igDP:CellValuePresenter}}}" Visibility="{Binding IsVisible,Converter={StaticResource BoolToVisibilityConverter}}"><local:RMTextBlock Text="{Binding Text}" Style="{StaticResource StringEditorTemplateTextBlockStyle}"/></Grid></ControlTemplate>
So , Neither using RelativeSource nor using TemplateBinding the Value is not the best way to bind. Can someone give me advice for this situation?
Hi Brandon,
I think I might be missing something here. Could you please create a small sample illustrating the approach with TemplateBinding so I could look further into it?
Thank you for reply. I just want to find a best solution to let the value showing is correct.
See the attachment.