我正在尝试在我的wp8应用中实现本地化。 当用户选择其中一个单选按钮时,我有两个单选按钮(阿拉伯语和英语),然后出现弹出窗口,如果他选择了确定,那么他确定要更改应用程序的语言然后应用程序的语言会发生变化但是如果他选择取消然后语言没有变化,但问题是即使用户按下取消,单选按钮也会切换。
如何停止切换?
这是我的Xaml代码和绑定的代码,如果选中了任何单选按钮..
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<StackPanel Orientation="Vertical" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="20">
<RadioButton Content="English" Foreground="Black" FontSize="30" IsChecked="{Binding isenglishchecked,Mode=TwoWay, Source={StaticResource appSettings}}" Checked="RadioButton_Checked"/>
<RadioButton Content="Arabic" Foreground="Black" FontSize="30" IsChecked="{Binding isarabicchecked,Mode=TwoWay, Source={StaticResource appSettings}}" Checked="RadioButton_Checked"/>
</StackPanel>
</Grid>
public bool isenglishchecked
{
get
{
return GetValueOrDefault<bool>(isenglishcheckedname, isenglishcheckedDefault);
}
set
{
var result = MessageBox.Show("This Will Change the Language of the App Do you Want to continue ?", "Language Change", MessageBoxButton.OKCancel);
if (result == MessageBoxResult.OK)
{
if (AddOrUpdateValue(isenglishcheckedname, value))
{
Save();
if (isenglishchecked)
{
Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-US");
Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("en-US");
MainViewModel.stationnamelist = null;
Messenger.Default.Send<string>("mainpage", "tomainpage");
(Application.Current.RootVisual as PhoneApplicationFrame).Navigate(new Uri("/MainPage.xaml", UriKind.Relative));
}
else
{
Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("ar-AE");
Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("ar-AE");
MainViewModel.stationnamelist = null;
Messenger.Default.Send<string>("mainpage", "tomainpage");
(Application.Current.RootVisual as PhoneApplicationFrame).Navigate(new Uri("/MainPage.xaml", UriKind.Relative));
}
}
}
else
{
(Application.Current.RootVisual as PhoneApplicationFrame).Navigate(new Uri("/Skins/SelectLanguage.xaml", UriKind.Relative));
}
}
}
public bool isarabicchecked
{
get
{
return GetValueOrDefault<bool>(isarabiccheckedname, isarabiccheckedDefault);
}
set
{
if (AddOrUpdateValue(isarabiccheckedname, value))
{
Save();
}
}
}
答案 0 :(得分:1)
可能发生的是,UI层(Silverlight)响应用户的点击,愉快地改变了自己的状态,然后设置了isenglishchecked或isarabicchecked的值。属性的值不会更改的事实无关紧要 - Silverlight没有注意到。 (不会因为设置调用而改变属性的值是非标准行为,因此Silverlight会像这样“行为不端”并不奇怪)
您可以尝试一些事项: