zoukankan      html  css  js  c++  java
  • WPF 控件之ComboBox绑定[2]

    最近感觉新的方法Binding comboBox用起来很好用。

    记录一下:

    <ComboBox Grid.Row="0" Grid.Column="1" VerticalAlignment="Center" HorizontalAlignment="Left" MinWidth="120"
                                  x:Name="cboFamilyName" 
                                  DisplayMemberPath="DisplayName"  
                                  SelectedValuePath="idRow" 
                                  IsEditable="True" 
                                  IsReadOnly="True"
                                  ItemsSource="{Binding MyList}"
                                  SelectedValue="{Binding Path=SelectedID, Mode=TwoWay}"
                                  />

    MyList就是某一个Model的list, Model中有idRow和DisplayName

    SelectedID表示选中的idRow,放到这个变量中。

    选中后,有时候会出现一个讨厌的红色矩形框。去掉矩形框方法(http://stackoverflow.com/questions/4135955/remove-red-rectangle-around-combobox):

    Validation.ErrorTemplate="{x:Null}"


    About modify the Validation.ErrorTemplate
    <ControlTemplate x:Key="ComboBoxValidationErrorTamplate">
                    <DockPanel>
                        <Border BorderBrush="Blue" BorderThickness="4">
                            <AdornedElementPlaceholder />
                        </Border>
                    </DockPanel>
                </ControlTemplate>
    And then use it in your ComboBox like
    <ComboBoxValidation.ErrorTemplate="{StaticResource ComboBoxValidationErrorTamplate}"
              ...>
  • 相关阅读:
    数论2&莫&杜
    虚树学习笔记
    LinkCutTree学习笔记
    FWT学习笔记
    容斥
    线段树合并
    线性基
    FFT_应用和例题
    斜率优化
    Redis中String的底层实现
  • 原文地址:https://www.cnblogs.com/mantian/p/3680291.html
Copyright © 2011-2022 走看看