currentDevicesをコレクションにリファクタリングすることは可能ですか? 基本的には、selectedValueがcurrentDevicesにバインドされている3つのコンボボックスがあります。 currentDevicesは設定ファイルから取得されます。View to Model to Settings
ビュー
<ComboBox ItemsSource="{Binding availableDevices}"
SelectedValue="{Binding currentDevice1}">
</ComboBox>
<ComboBox ItemsSource="{Binding availableDevices}"
SelectedValue="{Binding currentDevice2}">
</ComboBox>
<ComboBox ItemsSource="{Binding availableDevices}"
SelectedValue="{Binding currentDevice3}">
</ComboBox>
のViewModel
public string currentDevice1 {
get
{
return SampleSettings.Default.Device1;
}
set
{
SampleSettings.Default.Device1 = value;
}
}
public string currentDevice2
{
get
{
return SampleSettings.Default.Device2;
}
set
{
SampleSettings.Default.Device2 = value;
}
}
public string currentDevice3
{
get
{
return SampleSettings.Default.Device3;
}
set
{
SampleSettings.Default.Device3 = value;
}
}
常に3つのデバイスがありますか?おそらくその価値はありません。キャメルではないことを除けば、その名前はひどいものです。私はあなたがこの質問をするために名前を変更したと仮定して、ここに座ります。 – Will
いいえ、可変数のデバイスが存在します。私も簡単にするために名前を変更しました。 –
次にEdの答えはこれを行う良い方法です。 – Will