【发布时间】:2014-09-28 05:09:54
【问题描述】:
我在我的 Windows Phone 8 项目中使用 Toolkit ListPicker 并已开始对其进行本地化。我遇到了一个问题,因为我不知道如何使用 ListPicker 来做到这一点。
<toolkit:ListPicker x:Name="lstClubsPick"
FontSize="30"
Grid.Column="1"
VerticalAlignment="Center"
SelectionMode="Single"
HorizontalAlignment="Center"
SelectedIndex="{Binding KolleSelectedIndex, Mode=TwoWay}"
CacheMode="BitmapCache"
ExpansionMode="FullScreenOnly" >
<toolkit:ListPickerItem Content="{Binding Path=LocalizedResources.chooseClub, Source={StaticResource LocalizedStrings}}"/>
<sys:String>Choose</sys:String>
<sys:String>D1</sys:String>
<sys:String>D2</sys:String>
<sys:String>D3</sys:String>
<sys:String>D4</sys:String>
<i:Interaction.Triggers>
<i:EventTrigger EventName="Tap">
<cal:ActionMessage MethodName="ClubClicked">
<cal:Parameter Value="{Binding ElementName=lstPivot,Path=SelectedItem, Mode=TwoWay}"></cal:Parameter>
<cal:Parameter Value="{Binding ElementName=lstClubsPick,Path=SelectedItem, Mode=TwoWay}"></cal:Parameter>
</cal:ActionMessage>
</i:EventTrigger>
</i:Interaction.Triggers>
所以我面临的问题是我不知道如何让<sys:String>Choose</sys:String> 在我的 AppResources.resx 中查找字符串。我试过这个:
<toolkit:ListPickerItem Content="{Binding Path=LocalizedResources.chooseClub, Source={StaticResource LocalizedStrings}}"/>
而不是<sys:string>,但这会使我的应用程序崩溃。我搜索了谷歌,这是我能找到的唯一可能的解决方案。任何人都可以帮助我?将不胜感激。
编辑 1:所以我已经使用 andreask 的解决方案更新了我的代码,但是我的 ListPicker 没有响应我在 viewModel 中添加的字符串。
private ObservableCollection<string> _data;
public ObservableCollection<string> Data
{
get
{
return _data;
}
set {
_data = value;
NotifyOfPropertyChange(() => Data);
}
}
Data = new ObservableCollection<string>();
Data.Add("Test");
<toolkit:ListPicker x:Name="lstClubsPick" FontSize="30" Grid.Column="1" VerticalAlignment="Center" SelectionMode="Single" HorizontalAlignment="Center" ItemsSource="{Binding Data}" SelectedIndex="{Binding KolleSelectedIndex, Mode=TwoWay}" CacheMode="BitmapCache" ExpansionMode="FullScreenOnly">
我做错了什么?
编辑 2:非常感谢您的回答,您肯定为我指明了正确的方向。我找到了解决我的问题的方法,我绑定了我的 Pivot 视图的 ItemsSource,然后我可以在我的视图模型中添加一个 ObservableCollection<string> 然后我可以从我的视图模型 LstItems[PivotSelectedIndex].Data = new ObservableCollection<string>(items); 再次运行此代码,其中 items 是一个字符串数组。所以在我的字符串数组中,我可以使用带有AppResources.YourResourceName 的应用程序资源创建一个字符串。
【问题讨论】:
标签: c# xaml windows-phone-7 windows-phone-8 listpicker