DataGrid and named tuples

Posted by: abellisomi on 4 April 2019, 12:14 am EST

    • Post Options:
    • Link

    Posted 4 April 2019, 12:14 am EST

    Hello,

    Can a DataGrid be bound on Named Tuples?

    e.g.

    var named = (first: "one", second: "two");
    

    And be able to use first and second as column bindings.

    e.g.

    <c1:DataGridTextColumn Binding="{Binding first}" />
    <c1:DataGridTextColumn Binding="{Binding second}" />
    
  • Posted 7 April 2019, 4:11 pm EST

    Hi,

    Named(or Value) Tuple exposes their items via fields instead of properties and hence can not be used for Binding(supports only properties) on Column in DataGrid. However, if possible, you can use Tuple(reference type) which exposes their items as properties (e.g. Item1, Item2 etc.).

    var item = new Tuple<string, string>($"Row : {i}, Col: One", $"Row: {i}, Col: Two");
    

    and in xaml:

    <c1:DataGridTextColumn Header="First" Binding="{Binding Item1}"/>
    <c1:DataGridTextColumn Header="Second" Binding="{Binding Item2}"/>
    

    Regards,

    Basant

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels