Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
370
How to bind KeyValuePair to XamDataGrid Field?
posted

Hi, I have  KeyValuePair<Guid, string> Property in my MVVM object. A collection of that object is the datasource of a xamdatagrid. I want to bind the value of the KeyValuePair to a xamdatagrid field.

That is, I want the grid to show the value only but it is now showing the both the guid and the value. Here is how I an binding. I appreciate some xaml sample.

<

 

 

igDP:Field Name="Priority" Width="Auto"/>

Thanks

 

Parents
  • 9836
    Suggested Answer
    posted

    You should be able to bind directly to the key or the value of the dictionary when you set the Name of your fields to Key or Value. You may also use UnboundField for some complex binding:

    XAML:

    <igDP:XamDataGrid x:Name="xdg">

                <igDP:XamDataGrid.FieldLayoutSettings>

                    <igDP:FieldLayoutSettings AutoGenerateFields="False" />

                </igDP:XamDataGrid.FieldLayoutSettings>

                <igDP:XamDataGrid.FieldLayouts>

                    <igDP:FieldLayout>

                        <igDP:Field Name="Key"/>

                        <igDP:Field Name="Value"/>

                        <igDP:UnboundField BindingPath="Value.MyProperty"/>

                    </igDP:FieldLayout>

                </igDP:XamDataGrid.FieldLayouts>

    </igDP:XamDataGrid>

     

    CodeBehind:

     

    public partial class MainWindow : Window

        {

            private Dictionary<string, MyClass> dict = new Dictionary<string, MyClass>();

     

            public MainWindow()

            {

                InitializeComponent();

                Loaded += new RoutedEventHandler(MainWindow_Loaded);

            }

     

            void MainWindow_Loaded(object sender, RoutedEventArgs e)

            {

                dict["key1"] = new MyClass() { MyProperty = "prop1" };

                dict["key2"] = new MyClass() { MyProperty = "prop2" };

                dict["key3"] = new MyClass() { MyProperty = "prop3" };

                dict["key4"] = new MyClass() { MyProperty = "prop4" };

     

                xdg.DataSource = dict;

            }

        }

     

    public class MyClass

        {

            public string MyProperty { get; set; }

        }

     

    Let me know if you have any questions with this matter.

    HTH, 

     

Reply Children
No Data