I have 2 xamcomboeditors in my Grid and selected item of first should pass as a string parameter to ObjectDataProvider of second. How to bind the selected item of first to method parameter of object data provider of second
<ObjectDataProvider x:Key="dbNames" MethodName="GetName" ObjectType="{x:Type myApp:NameList}" > <ObjectDataProvider.MethodParameters> <x:Static Member="sys:String.Empty" /> </ObjectDataProvider.MethodParameters> </ObjectDataProvider>
<ObjectDataProvider x:Key="dbSNames" MethodName="GetSName" ObjectType="{x:Type myApp:SNameList}" > </ObjectDataProvider>
<ig:XamComboEditor x:Name="cmbBrowse" Height="20" Width="100" Padding="3,2" Margin="10 0 0 0" IsEditable="True" AllowFiltering="True" AutoComplete="True" OpenDropDownOnTyping="False" VerticalAlignment="Center" HorizontalAlignment="Left" Grid.Row="1" ItemsSource="{Binding Source={StaticResource dbSNames}}"> </ig:XamComboEditor> <ig:XamComboEditor Name="cmbName" Height="20" Width="180" Padding="3,2" AllowMultipleSelection="False" IsEditable="False" Grid.Row="2" ItemsSource="{Binding Source={StaticResource dbNames}}" Margin="0 0 300 0"> </ig:XamComboEditor>
Code Behind:
public class NameList { public ObservableCollection<TypeList> GeName(string name) { if (!string.IsNullOrEmpty(servername)) { ObservableCollection<string> lst = Program.GetCollectionFromDataset(Program.GetName(name)); if (lst == null) return new ObservableCollection<TypeList>(); else { ObservableCollection<TypeList> cst = new ObservableCollection<TypeList>(); foreach (string s in lst) { cst.Add(new TypeList(s)); } return cst; } } else return new ObservableCollection<TypeList>(); } }
public class SNameList { public ObservableCollection<TypeList> GetSName() { ObservableCollection<string> lst = Program.GetCollectionFromDataset(Program.GetSName()); if (lst == null) return new ObservableCollection<TypeList>(); else { ObservableCollection<TypeList> cst = new ObservableCollection<TypeList>(); foreach (string s in lst) { cst.Add(new TypeList(s)); } return cst; } } } #endregion
public class TypeList { public string fieldOptions { get; set; } public TypeList() { fieldOptions = null; } public TypeList(string a) { fieldOptions = a; } }
Hi hlhz,
The first thing you need to do is modify the parameters your GetName method accepts. Right now you take in a string but since you bind the comboeditor to a collection of TypeList the SelectedItem property of the editor is going to return a TypeList object. So modify your GetName method to accept a TypeList object instead of a string and then alter the XAML for the method parameters.
<ObjectDataProvider x:Key="dbNames" MethodName="GetName" ObjectType="{x:Type myApp:NameList}" > <ObjectDataProvider.MethodParameters> <x:NullExtension/> </ObjectDataProvider.MethodParameters> </ObjectDataProvider>
Now add this XAML to the comboeditor:
<ig:XamComboEditor.SelectedItem> <Binding Source="{StaticResource dbNames}" Path="MethodParameters[0]" BindsDirectlyToSource="True"/> </ig:XamComboEditor.SelectedItem>
When you select a value from this comboeditor, it will update the SelectedItem property which will then update the method parameters for the object data provider.
Here is the sample I used to test this. Let me know if you have any questions on this.