当SelectedItem为null时,如何使用DataTemplate设置Combobox的Text属性?

时间:2015-10-03 22:11:02

标签: wpf xaml combobox

以下代码有效,直到我尝试将SelectedInsurance为空时可视化“ - 请选择保险 - ”:

 <Style x:Key="PrimaryInsuranceStyle" TargetType="{x:Type ComboBox}">
            <Setter Property="Height" Value="36" />
            <Style.Triggers>
                <DataTrigger Binding="{Binding Path=PrimaryInsurance.SelectedInsurance}" Value="{x:Null}">
                    <Setter Property="Text" Value="-- Please Select Insurance --" />
                </DataTrigger>
            </Style.Triggers>
        </Style>

  <DataTemplate x:Key="InsuranceTemplate">
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="20" />
                    <!--Company Name-->
                    <ColumnDefinition Width="220" />
                    <!--Effective Date From-->
                    <ColumnDefinition Width="56" />
                    <ColumnDefinition Width="16" />
                    <!--Effective Date To-->
                    <ColumnDefinition Width="56" />
                    <!--Empty space-->
                    <ColumnDefinition Width="14" />
                    <!--Insurance Type-->
                    <ColumnDefinition Width="100" />
                </Grid.ColumnDefinitions>
                <TextBlock Text="{Binding XNotInEffect}"      Grid.Column="0" />
                <TextBlock Text="{Binding CompanyName}"       Grid.Column="1"/>
                <TextBlock Text="{Binding EffectiveDateFrom}" Grid.Column="2" TextAlignment="Center" />
                <TextBlock Text="--" Grid.Column="3" TextAlignment="Center" />
                <TextBlock Text="{Binding EffectiveDateTo}"   Grid.Column="4" TextAlignment="Center" />
                <TextBlock Text="{Binding PolicyType}"        Grid.Column="6" />
            </Grid>
        </DataTemplate>



<ComboBox 
            Style="{StaticResource PrimaryInsuranceStyle}"
            HorizontalAlignment="Left" Margin="590,51,0,0" VerticalAlignment="Top" Width="510" 
            IsEnabled="{Binding PrimaryInsurance.CanPickInsurance}"
            ItemsSource="{Binding PrimaryInsurance.AllPatientInsurance}" 
            ItemTemplate="{StaticResource InsuranceTemplate}"
            SelectedItem="{Binding PrimaryInsurance.SelectedInsurance}"
            />

当selectedItem有一个DataTemplate并且selecteditem为null时,如何设置Combobox的Text属性?

注意:可视化文本为空。

TIA

0 个答案:

没有答案