I have a couple of questions.
i want to use the same xamdatagrid for several different data sources. The reason is that only a few data columns differ. The others are the same. instead of defining two different data grids in xaml and styling the columns there I use the same one and I style the fields in the code behind. So I have
private void OnFieldLayoutInitialized(object sender, FieldLayoutInitializedEventArgs e) {
if(gridtype1){
var vgDownStyle = new Style(typeof(XamComboEditor)); vgDownStyle.Setters.Add(new Setter(XamComboEditor.ItemsProviderProperty, new DynamicResourceExtension("ValveGroupList1")));
vgDownStyle.Setters.Add(new Setter(XamComboEditor.DisplayMemberPathProperty, new DynamicResourceExtension("ValveGroupName")));
e.FieldLayout.Fields["VG"].Settings.EditorStyle = vgDownStyle;
}else if (gridtype2) {
var vgDownStyle = new Style(typeof(XamComboEditor));vgDownStyle.Setters.Add(new Setter(XamComboEditor.ItemsProviderProperty, new DynamicResourceExtension("ValveGroupList2")));
e.FieldLayout.Fields["ValveGroupList2"].Settings.EditorStyle = vgDownStyle;
}
is the above code the same as
<ComboBox Grid.Row="1 ItemsSource="{Binding ValveGroupList1}" DisplayMemberPath="ValveGroupName">
In terms of the bolded text?
If so it's not binding.
second question is (in the same event method as above)
If I have a loop
foreach (var field in e.FieldLayout.Fields) {
is there a way to loop only through fields that contain a specific character?
Thanks
Hi Kris,
You code looks good but just in case this looks like a reference you need in case I’m missing something in your code snippet.
http://help.infragistics.com/doc/WPF/2014.2/CLR4.0/?page=xamComboEditor_Setting_the_xamComboEditor_as_an_Editor_of_a_Field_Programmatically.html
This is the equivalent xaml code for comparison:
http://help.infragistics.com/doc/WPF/2014.2/CLR4.0/?page=xamComboEditor_Using_xamComboEditor_to_Edit_a_Field_in_xamDataGrid.html
I just noticed one thing. Are you binding to a XamComboEditor or have you added a template with a ComboBox to the field? Your OnFieldLayoutInitialized code references the XamComboEditor but the xaml appears to be a ComboBox.
As for your second questions, perhaps you could use linq to create a collection of the specific fields/items you want to review and then loop thru those and reference the specific fields you were interested in (i.e. e.FieldLayout.Fields[fieldname] once you know the name of the field).
Thanks for your suggestion. From the examples provided this is what I have:
In my view model:
public List<string> NorthValveGroupList { get { return _northValvegGroupList; } set { Set(() => NorthValveGroupList, ref _northValvegGroupList, value); } }
in my code behind:
var vgListStyle = new Style(typeof(XamComboEditor)); var vgListSetter = new Setter(XamComboEditor.ItemsProviderProperty, FindResource("NorthValveGroupListKey")); vgListStyle.Setters.Add(vgListSetter); e.FieldLayout.Fields["VG"].Settings.EditorStyle = vgListStyle; e.FieldLayout.Fields["VG"].Width = new FieldLength(55);
in my xaml:
<UserControl.Resources> <igWPF:ComboBoxItemsProvider x:Key="NorthValveGroupListKey" ItemsSource="{Binding NorthValveGroupList}" DisplayMemberPath="ValveGroupName" />
</UserControl.Resources>
but it's still not binding. The data context is set correctly since my xamGridView properly binds and I can see data but not the XamComboBox. If I debug my code I can that NorthValveGroupList get's populated.
ComboBoxItemsProvider does not have a DataContext so binding to the ItemsSource property like that is not going to work. You should bind your NorthValveGroupList directly to the XamComboEditor's ItemsSource property instead. You can set the value in the Setter constructor to a Binding rather than assigning the collection directly.
Style style = new Style(typeof(XamComboEditor));
style.Setters.Add(new Setter(XamComboEditor.ItemsSourceProperty, new Binding("NorthValveGroupList")));
Hello. Unfortunately it's still not working. I've attached a small sample project. Please have a look. Your help is greatly appreciated.
Thanks for the sample. From it I was able to tell what the issue was.
The Binding code I sent you was more of an example rather than the definitive code you need to use. In the case of your sample, the Binding needs to use RelativeSource to go up to the Window and then bind to the DataContext.ComboList property. I've attached a modified version of your sample with the changes.
I do have one more question. I need to bind a data table to this xamComboEditor. From you two suggestions I chose to bind the data in the xaml
<Style x:Key="VGStatusCodesStyle" TargetType="{x:Type igWPF:XamComboEditor}"> <Setter Property="ItemsSource" Value="{Binding RelativeSource={RelativeSource AncestorType={x:Type UserControl}}, Path=DataContext.ValveGroupStatusCodes}"/></Style>
How would I change the syntax to it displays a data table?
I believe you need to bind the XamComboEditor's ItemsSource to the DataTable.DefaultView. Like the XamDataGrid, you can't bind directly to the DataTable. So you might want to make your ValveGroupStatusCodes property a DataView instead and when you set it's value, set it to your DataTable.DefaultView.