通貨アイテムのリストにバインドされたリストボックスがあります。通貨はクラスです
public class Currency
{
public string code { get; set; }
public string countryName { get; set; }
public string imgUrl { get; set; }
public string infoLink { get; set;} }
}
リスト ボックスは通貨オブジェクトのリストにバインドされ、このリスト ボックスの各項目は画像とテキスト ブロックのスタック パネルです。
SelectedItem プロパティをコード ビハインドのプロパティにバインドして追いつきたい
<ListBox Name="sCurrencyLB" Margin="10,0,0,0" Width="Auto" Height="180"
IsEnabled="{Binding IsChecked, ElementName=LiveTilesToggleBtn}"
SelectedItem="{Binding STileCurrency, Mode=TwoWay,
Source={StaticResource livetilemanager}}"
ItemsSource="{Binding SCurrencyList}" >
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal" Margin="0,10,0,0">
<TextBlock Name="scountryNametb" Width="50" Text="{Binding code}"
VerticalAlignment="Center" HorizontalAlignment="Right"/>
<Image Source="{Binding imgUrl}" Height="50" Width="50"
HorizontalAlignment="Left" />
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
リストボックスで選択されたアイテムである必要があるプロパティのコード
private Currency sTileCurrency;
public Currency STileCurrency
{
get
{
return appSettings.GetValueorDefault<Currency>("STileCurrency", null);
}
set
{
if (appSettings.AddOrUpdateValue("STileCurrency", value))
{
settings.Save();
}
}
}
注: XAML 内のプロパティを含む Class のインスタンスを作成しました