2017-06-21 91 views
-2

我想重置組合框以清空它, 我有一個示例正確,但另一個是錯誤的。如何在WPF中重置組合框

兩個組合框結合到枚舉列表:

  • 枚舉商標:

    公共枚舉IdentificationDeviceBrand:整數 { FMC = 1, DMM = 2, HTC = 3 }

  • 枚舉類型:

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

    }

我製成組合框的復位:

  • 對於Type是OK

    comboType.SelectedIndex = -1; 它會清除沒有任何消息:enter image description here

  • 但第二Combobx BRAND comboBrand.SelectedIndex = -1;, 我有一個消息: 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

如果你只是想擺脫文字,你應該刪除Validation.ErrorTemplate屬性:

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

非常感謝,它現在工作正常 – devtunis