У меня есть три ComboBox. Threre связаны с тем же ItemsSource.Как я могу связать множество элементов ComboBoxСвязь друг с другом
Этот тип ItemsSouce является Dictionary<string, Dictionary<CustomKey, CustomClass>>
CustomKey
public struct CustomKey<T1,T2> // T1, T2 is string
{
public readonly T1 Symbol;
public readonly T2 Column;
public CustomKey(T1 key1, T2 key2) { Symbol = key1; Column = key2; }
}
CustomClass
public class CustomClass
{
public string Value{get;set}
}
Во-первых. ItemsSoure FirstComboBox является Dictionary.Keys
Второй. Я хочу установить элементы Second ComboBox Source - это SelectedItems FirstComboBox.
как это словарь [FirstComboBox.SelectedItem] .Keys T1
В-третьих. ThirdComboBox в ItemsSource словарь [FirstComboBox.SelectedItem] .Keys T2
Последний.
Это мой код ...
// Source.GetNames is ItemsSource.Keys.ToList();
protected virtual FrameworkElement CreateAutoCompleteComboBoxControl(PropertyItem property)
{
var c = new AutoCompleteComboBox();
ContinuityBindablePropertyItem cbp = (property as ContinuityBindablePropertyItem); // cbp is First ComboBox SelectedItem Descriptor. but i don't know how to use...
if (property.DisplayName == "Sheet") // First ComboBox
{
c.SetBinding(ItemsControl.ItemsSourceProperty, new Binding("Source.GetSheetNames");
}
else if (property.DisplayName == "TestName") // Second ComboBox
{
c.SetBinding(ItemsControl.ItemsSourceProperty, new Binding("Source.GetSheetNames");
}
else if (property.DisplayName == "Symbol") // Third ComboBox
{
c.SetBinding(ItemsControl.ItemsSourceProperty, new Binding("Source.GetSheetNames");
}
c.SetBinding(ComboBox.TextProperty, property.CreateBinding());
return c;
}
Просьба помочь мне. Я плохо говорю по-английски. Надеюсь, вы понимаете.
спасибо.
РЕДАКТИРОВАТЬ метод изменения.
protected virtual FrameworkElement CreateAutoCompleteComboBoxControl(PropertyItem property)
{
StackPanel s = new StackPanel();
var c1 = new AutoCompleteComboBox { Name = "c1", DisplayMemberPath = "Key", IsEditable = property.IsEditable, ItemsSource = property.ItemsSource, VerticalContentAlignment = VerticalAlignment.Center };
var c2 = new AutoCompleteComboBox { IsEditable = property.IsEditable, ItemsSource = property.ItemsSource, VerticalContentAlignment = VerticalAlignment.Center };
var c3 = new AutoCompleteComboBox { IsEditable = property.IsEditable, ItemsSource = property.ItemsSource, VerticalContentAlignment = VerticalAlignment.Center };
c1.SetBinding(ItemsControl.ItemsSourceProperty, new Binding("Source") { Source = MappingService.Instance, Mode = BindingMode.OneWay });
c2.SetBinding(ItemsControl.ItemsSourceProperty, new Binding("Values") { Source = c1.SelectedItem, Mode = BindingMode.OneWay });
c3.SetBinding(ItemsControl.ItemsSourceProperty, new Binding("SelectedItem.Values") { ElementName = c1.Name, Mode = BindingMode.OneWay });
c1.SetBinding(ComboBox.TextProperty, property.CreateBinding());
c2.SetBinding(ComboBox.TextProperty, property.CreateBinding());
c3.SetBinding(ComboBox.TextProperty, property.CreateBinding());
s.Children.Add(c1);
s.Children.Add(c2);
s.Children.Add(c3);
return s;
}
я пытаюсь привязки пути 'значения', 'Value', 'SelectedItem.Value', «SelectedItem.Values, Изменить источник для C1.SelectedItem или элемента имя = c1 ...
но это не работает
Редактировать
Добавление изображения.
У вас есть xaml, или вы все делаете в коде? – Joe
@joe да я не ues xaml. только код за – user3214694
Что такое itemSource вашего первого combobox. Можете ли вы добавить полную структуру? это не очень понятно. Я хочу установить Second ComboBox. Items Source - это SelectedItems FirstComboBox. как этот словарь [FirstComboBox.SelectedItem] .Keys T1 В-третьих. ThirdComboBox's ItemsSource Dictionary [FirstComboBox.SelectedItem] .Keys T2 – Nitin