C# 如何更改windows Phone 8中选定的单选按钮?

C# 如何更改windows Phone 8中选定的单选按钮?,c#,windows-phone-8,radio-button,C#,Windows Phone 8,Radio Button,我正在尝试在我的wp8应用程序中实现本地化。 我有两个单选按钮(阿拉伯语和英语)当用户选择其中一个单选按钮时,弹出窗口显示他是否确定要更改应用程序的语言如果他选择“确定”,则应用程序的语言会更改,但如果他选择“取消”,则语言不会更改,但问题是即使用户按下“取消”,单选按钮也会切换 如何阻止切换发生 这是我的Xaml代码,如果选中任何单选按钮,该代码将被绑定 <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">

我正在尝试在我的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();
                }
            }
        }

公共图书馆正在检查中
{
得到
{
返回GetValuerDefault(isenglishcheckedname,isenglishcheckedDefault);
}
设置
{
var result=MessageBox.Show(“这将更改应用程序的语言是否要继续?”,“语言更改”,MessageBoxButton.ok取消);
if(result==MessageBoxResult.OK)
{
if(AddOrUpdateValue(isenglishcheckedname,值))
{
Save();
如果(已选中)
{
Thread.CurrentThread.CurrentCulture=新系统.Globalization.CultureInfo(“en-US”);
Thread.CurrentThread.CurrentUICulture=新系统.Globalization.CultureInfo(“en-US”);
MainViewModel.stationnamelist=null;
senger.Default.Send(“主页”、“tomainpage”);
(Application.Current.RootVisual作为PhoneApplicationFrame)导航(新Uri(“/MainPage.xaml”,UriKind.Relative));
}
其他的
{
Thread.CurrentThread.CurrentCulture=新系统.Globalization.CultureInfo(“ar AE”);
Thread.CurrentThread.CurrentUICulture=新系统.Globalization.CultureInfo(“ar AE”);
MainViewModel.stationnamelist=null;
senger.Default.Send(“主页”、“tomainpage”);
(Application.Current.RootVisual作为PhoneApplicationFrame)导航(新Uri(“/MainPage.xaml”,UriKind.Relative));
}
}
}
其他的
{
导航(新Uri(“/Skins/SelectLanguage.xaml”,UriKind.Relative));
}
}
}
公共图书馆
{
得到
{
返回GetValuerDefault(isarabiccheckedname,isarabiccheckedDefault);
}
设置
{
if(AddOrUpdateValue(isarabiccheckedname,值))
{
Save();
}
}
}

可能发生的情况是,UI层(Silverlight)响应用户的点击,愉快地更改自己的状态,然后设置isenglishchecked或isarabicchecked的值。属性的值没有改变这一事实并不重要——Silverlight没有注意到。(不更改属性值以响应set调用是非标准行为,因此Silverlight会像这样“行为不当”也就不足为奇了)

您可以尝试以下几点:

  • 在两个属性的集合处理程序中,引发isenglishchecked和isarabicchecked的PropertyChanged事件(在INotifyPropertyChanged中)。这将导致UI重新查询视图模型,使其重新与视图模型同步。如果选中的属性没有更改,UI将注意到这一点
  • 在每个单选按钮上使用内置按钮,如果用户取消操作,则在集合处理程序中引发异常。这可能会导致单选按钮的值不变(良好),但也可能使按钮变为红色
  • 定义你自己的。在ValidationRule.Validate期间显示消息框可能会更好
  • 完全放弃确认对话框,立即更改语言即可。如果是错误,用户只需点击另一个按钮即可

  • 谢谢你的回复,迈克,但我昨天才解决了这个问题。。。顺便说一下,谢谢