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
How to bind Datasoure to Xamdatagrid if Source is Dictionary with in Dictionary. (I mean Nested Dictionaries).
What if like in my case Value is of type object. I noticed that the xamDataGrid cannot allow editing this because it cannot know the type of the object. Suppose I want the data grid to assume it is a string...
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,