DataGrid and named tuples

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

  • Posted 4 April 2019, 12:14 am EST

    Can a DataGrid be bound on Named Tuples?

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

    And be able to use first and second as column bindings.
    <c1:DataGridTextColumn Binding="{Binding first}" />
    <c1:DataGridTextColumn Binding="{Binding second}" />

  • Marked as Answer

    Replied 7 April 2019, 4:11 pm EST


    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}"/>

Need extra support?

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

Learn More

Forum Channels