2つのComboBoxを含む独自のユーザーコントロールを設定しました。各ComboBoxアイテムソースはDependencyPropertyにバインドされています。私が抱えている問題は、ユーザーコントロールを使用するフォームからユーザーコントロールにプロパティを渡すことです。
以下は私のユーザーコントロールです:
public static readonly DependencyProperty ListOneProperty = DependencyProperty.Register
("ListOne", typeof(List<int>), typeof(LinkedComboBox), new PropertyMetadata(new List<int>()));
public List<int> ListOne
{
get { return (List<int>)GetValue(ListOneProperty); }
set { SetValue(ListOneProperty, value); }
}
public static readonly DependencyProperty ListTwoProperty = DependencyProperty.Register
("ListTwo", typeof(List<string>), typeof(LinkedComboBox), new PropertyMetadata(new List<string>()));
public List<string> ListTwo
{
get { return (List<string>)GetValue(ListTwoProperty); }
set { SetValue(ListTwoProperty, value); }
}
public LinkedComboBox()
{
InitializeComponent();
FillListOne();
}
そして、以下は私のMainWindowxamlです。
<control:LinkedComboBox x:Name="LinkedBox" ListTwo="{Binding MyList}"/>
およびMainWindow.xaml.cs:
static List<string> _myList = new List<string>{"abc","efg"};
public List<string> MyList
{
get { return _myList; }
set { _myList = value; }
}
public MainWindow()
{
InitializeComponent();
}
メインウィンドウからバインディングを受け入れるためにユーザーコントロールを取得するには何が必要ですか?