2017-06-21 9 views
-2

コンボボックスをリセットして空にするには、 私は正しい例が1つありますが、もう1つは間違っています。コンボボックスをWPFでリセットするには

列挙リストへの2つのコンボボックスのバインド:

  • 列挙ブランド:

    パブリック列挙IdentificationDeviceBrand:int型 { FMC = 1、 DMM = 2、 HTC = 3 }

  • 列挙型:

    public enum IdentificationTypes : int 
    { 
        TerminalEntryGate = 1, 
        TerminalExitGate = 2, 
        LoadingAreaEntryGate = 3, 
        LoadingAreaExitGate = 4, 
        IslandEntryGate = 5, 
        IslandExitGate = 6 
    

    }

Iは、コンボボックスのリセットを行った:タイプについて

  • がOKである

    comboType.SelectedIndex = -1。 それは、任意のメッセージを表示せずにクリアされます:コンボボックスのBRANDの enter image description here

XAML:

<ComboBox Name="comboBrand" 
      Validation.ErrorTemplate="{StaticResource TextBoxErrorTemplate}" 
      ItemsSource="{Binding BrandEnum}" SelectedItem="{Binding SelectedBrand, NotifyOnValidationError=True, TargetNullValue=''}" 
      SelectedValuePath="id" /> 
+3

XAMLマークアップを投稿し、問題を再現できるサンプルを含めてください:https://stackoverflow.com/help/mcve – mm8

答えて

1

もしenter image description here

  • しかし、二CombobxのBRAND comboBrand.SelectedIndex = -1;、 私がメッセージを持っています単にテキストを取り除きたい場合は、Validation.ErrorTemplate属性を削除する必要があります:

    <ComboBox Name="comboBrand" 
        ItemsSource="{Binding BrandEnum}" 
        SelectedItem="{Binding SelectedBrand, NotifyOnValidationError=True, TargetNullValue=''}" 
        SelectedValuePath="id" /> 
    
  • +0

    ありがとうございます – devtunis

    関連する問題