Hello. I have an XamDataGrid of objects; each object has two properties I want to edit within the grid. I'm creating my FieldLayout programatically, to allow a varying number of columns. When I define my layout, I can set the binding for each Field so the PropertyPath points to a particular column in my ViewModel ((i.e. Path="Columns[0]", Path="Columns[1]", etc.) This works fine:
http://imgur.com/rJLCKiR
I want to apply a template to the CellValuePresenter to let me edit each field, with one textbox bound to each of the two fields:
http://imgur.com/9IEq1Du
As you can see, the template bindings aren't correct. Right now, the template has bindings to one of the columns (Path="DataItem.Columns[0]"), since I can't figure out a simple way to get the index for each column into the template. What I really want is for the CellValuePresenter to get the correct bound object, defined in my FieldLayout, but bind each textbox to the appropiate property.
Any help would be vastly appreciated.
Hello Ed,
Thank you for your feedback. I am glad that you resolved your issue and I believe that other community members may benefit from this as well.
Thanks again.
Heh, don't even need the converter anymore.
<TextBox Text="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type igWPF:CellValuePresenter}}, Path=Value.Age}"/>
Aha! I think I figured it out.
<Window.Resources> <ResourceDictionary> <local:InfoConverter x:Key="InfoConverter" /> <Style TargetType="{x:Type igWPF:CellValuePresenter}" x:Key="InfoStyle"> <Setter Property="BorderThickness" Value="2"/> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type igWPF:CellValuePresenter}"> <StackPanel> <Border BorderBrush="Black" BorderThickness="2"> <StackPanel> <StackPanel Orientation="Vertical"> <Label Content="Name:" /> <TextBox Text="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type igWPF:CellValuePresenter}}, Path=Value, ConverterParameter=age, Converter={StaticResource InfoConverter}}"/> </StackPanel> <StackPanel Orientation="Vertical"> <Label Content="Age:" /> <TextBox Text="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type igWPF:CellValuePresenter}}, Path=Value, ConverterParameter=name, Converter={StaticResource InfoConverter}}"/> </StackPanel> </StackPanel> </Border> </StackPanel> </ControlTemplate> </Setter.Value> </Setter> </Style> </ResourceDictionary> </Window.Resources>
Sorry I haven't replied earlier. Thanks for looking into this.
The problem with the solution you posted is that it tightly couples the definition of the template to the UnboundField, which I would like to avoid. Ideally, the definition of where the UnboundField gets its data from, and the way that data is styled, should be completely independent from each other...the field says "get the data from this element of the array" and the style says "wherever the data comes from, display this field in text box A".
Thanks,
Ed
I am just checking if you got this worked out or you still require any assistance or clarification on the matter.