2014-02-21 258 views
0

我試圖做一個CASE的選項質量,但我收到「==」的操作員錯誤什麼是這個問題的解決方案。選擇一個組合框項目XAML

這背後

private void myComboBoxThatICreatedInXaml_SelectionChanged(object sender, SelectionChangedEventArgs e) 
    { 

     if (myComboBoxThatICreatedInXaml.SelectedValue.ToString == Low) 
     { 
      QualityChoices.Add(YouTubeQuality.QualityHigh); 

      case 
       (myComboBoxThatICreatedInXaml.SelectedValue.ToString == Medium) 
      { 
       QualityChoices.Add(YouTubeQuality.QualityMedium); 
      } 
      case 
       (myComboBoxThatICreatedInXaml.SelectedValue.ToString == High) 
      { 
       QualityChoices.Add(YouTubeQuality.QualityHigh); 
      } 

     } 

的代碼,這是我的XAML代碼。

<ComboBox x:Name="myComboBoxThatICreatedInXaml" SelectionChanged="myComboBoxThatICreatedInXaml_SelectionChanged" > 
      <ComboBoxItem Tag="LW">Low</ComboBoxItem> 
      <ComboBoxItem Tag="MD">Medium</ComboBoxItem> 
      <ComboBoxItem Tag="HG">High</ComboBoxItem> 
     </ComboBox> 

回答

3

你有一些C#語法問題去那裏。您需要()ToString方法和引用的標誌字符串文字周圍:

if (myComboBoxThatICreatedInXaml.SelectedValue.ToString() == "Low") 

如果你想使用switch語句,則是這樣的:

switch(myComboBoxThatICreatedInXaml.SelectedValue.ToString()) 
{ 
    case "Low": 
     QualityChoices.Add(YouTubeQuality.QualityHigh); 
     break; 
    case "Medium": 
     QualityChoices.Add(YouTubeQuality.QualityMedium); 
     break; 
    case "High": 
     QualityChoices.Add(YouTubeQuality.QualityHigh); 
     break; 
    default: 
     break; 
} 
+0

謝謝!它的工作現在! – Mikasuki

相關問題