2013-06-24 54 views
0

我想在我的wp8應用程序中實現本地化。 當用戶選擇一個單選按鈕時,我有兩個單選按鈕(阿拉伯語和英語),然後出現彈出窗口,他確信他想更改應用程序的語言,如果他選擇了確定,那麼應用程序的語言會改變,但如果他選擇取消,然後語言不會改變,但問題是即使用戶按下取消,單選按鈕也會切換。如何更改在Windows Phone 8中選定的單選按鈕?

如何停止切換髮生?

這是我的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(); 
       } 
      } 
     } 

回答

1

什麼是有可能發生的是,UI層(Silverlight的),以響應用戶的敲擊,高高興興更改自己的狀態,然後設置isenglishchecked或isarabicchecked的值。事實上,屬性的值不是的變化是沒有意義的 - Silverlight沒有注意到。 (響應組呼叫不改變屬性的值是不規範的行爲,所以它並不奇怪,Silverlight的將「胡作非爲」像這樣)

有一些事情你可以嘗試:

  1. 在這兩個屬性的集合處理程序中,引發PropertyChanged事件(在INotifyPropertyChanged中)進行isenglishchecked和isarabicchecked。這將導致用戶界面重新查詢視圖模型,以便它恢復同步。如果選中的屬性沒有改變,UI將會注意到這一點。
  2. 在每個RadioButton上使用內置的ExceptionValidationRule,然後在Set處理程序中拋出異常,如果用戶取消該操作。這可能會導致單選按鈕的值不會改變(好),但也可能會使按鈕變紅。
  3. 定義您自己的ValidationRule。在ValidationRule.Validate期間顯示消息框可能會更好。
  4. 完全丟棄確認對話框,只需立即更改語言。如果這是一個錯誤,用戶只需點擊另一個按鈕。
+0

感謝您的回覆邁克,但我昨天解決了問題只...謝謝你的方式 –

相關問題