Hi,
I have a class
class Test{ string name; List<string> values}
And I have a Dictionary <int, Test>. Now I have to bind this data to a xamdatagrid such that I have 2 columns, one with the name and other with the values. The number of rows created for every Test object should be equivalent to the number of values in the List.
Is it possible to achieve this?
Thanks
Hello Viswanath,
I had missed your earlier question on the Unbound field. In 14.2 changes were made wherein any field can be configured to be an unbound field by setting the Fields binding type to Unbound rendering the Unbound field obsolete. To learn more about these changes please see: http://help.infragistics.com/doc/WPF/2016.1/CLR4.0/?page=Whats_New_in_2014_Volume_2.html.
Sincerely,
Valerie
Software Developer
Infragistics Inc
Since in this case we are re-templating the CellValuePresenter and need to create a control template the best method to do this is to create the CellValuePresenterStyle in XAML and then attach it to the field in code behind. For example:
XAML:
<Window.Resources>
<local:MyConverter x:Key="Conv"/>
<Style x:Key="style1" TargetType="{x:Type igDP:CellValuePresenter}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type igDP:CellValuePresenter}">
<ListBox ItemsSource="{Binding DataItem.Value,
Converter={StaticResource Conv},ConverterParameter=Test}" />
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Window.Resources>
C#:
UnboundField ValuesField = new UnboundField();
Style style = (Style) this.Resources["style1"];
FieldSettings fs = new FieldSettings();
fs.CellValuePresenterStyle = style;
ValuesField.Settings = fs;
Can you also tell me, how to define the third column in the example (the one with lists in each cell) programmatically?
Hi Valerie,
Thank you for the response. The suggested method works. But, I am getting the following alert when I try to use UnboundField.
Unbound field is obsolete: Use Field (or one of its editor specific derived classes) with the new BindingType property set to 'Unbound' or 'UseAlternateBinding' instead. The new 'AlternateBinding' and 'AlternateBindingRetentionMode' properties replace all the UnboundFields 'Binding...' properties.
You need to set the binding on the unbound field, for example:
UnboundField NameField = new UnboundField();
NameField.Label = "Name";
MyConverter conv = new MyConverter();
Binding binding = new Binding();
binding.Converter = conv;
binding.ConverterParameter = "Name";
NameField.Binding = binding;