我有三個ComboBox。 Threre綁定的是相同的ItemsSource。我怎樣綁定很多ComboBox的ItemsSoure互相連接
這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}
}
首先。 FirstComboBox的ItemsSoure是Dictionary.Keys
二。我想設置第二個組合框的項目源是FirstComboBox的SelectedItems。
這樣字典[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;
}
我嘗試綁定路徑 '價值', '價值', 'SelectedItem.Value',「SelectedItem.Values,輸入源切換至C1.SelectedItem或元素名稱= C1 ...
但它的不工作
你有任何xaml,或者你在做代碼中的一切嗎? – Joe
@joe是的,我不用你的xaml。僅在 – user3214694
後面的代碼什麼是您的第一個組合框的itemSource。你能添加完整的結構嗎?這不是很清楚第二。我想設置Second ComboBox的Items Source是FirstComboBox的SelectedItems。 今日語言字典[FirstComboBox.SelectedItem] .Keys T1 三。 ThirdComboBox的ItemsSource字典[FirstComboBox.SelectedItem] .Keys T2 – Nitin