1

私はWPFの初心者です。私はコンボボックスでこの問題を抱えています。

コンボボックスが初めてレンダリングされ、表示するものが何もない場合、コンボボックスの境界線を赤に設定する必要がありますが、残念ながらそうではありません。

コードスニペットを見つけてください

<Style x:Key="requiredFieldValidationStyleComboBox">
    <Style.Triggers>
        <DataTrigger Binding="{Binding RelativeSource={RelativeSource Self}, Path=SelectedItem.Content}" Value="{x:Null}">
            <Setter Property="ComboBox.BorderBrush" Value="{StaticResource FaultyBorderBrush}" />
            <Setter Property="ComboBox.ToolTip" Value="Input value is mandatory" />
        </DataTrigger>
    </Style.Triggers>
</Style>
4

2 に答える 2

0

I found your style to work perfectly once I added it to a combo box, make sure the combo box actually has it's style property set or remove the x:Key property if you want it to apply to all combo boxes.

 <Window.Resources>
        <Style x:Key="requiredFieldValidationStyleComboBox">
            <Style.Triggers>
                <DataTrigger Binding="{Binding RelativeSource={RelativeSource Self}, Path=SelectedItem.Content}" Value="{x:Null}">
                    <Setter Property="ComboBox.BorderBrush" Value="Red" />
                    <Setter Property="ComboBox.ToolTip" Value="Input value is mandatory" />
                </DataTrigger>
            </Style.Triggers>
        </Style>
    </Window.Resources>
    <Grid Margin="0,0,401,279">
        <ComboBox Style="{StaticResource requiredFieldValidationStyleComboBox}" Margin="46,66,-46,-66"/>
    </Grid>

Nothing selected

Selected

于 2012-11-20T10:59:30.980 に答える
0

selectedItem にバインドするオブジェクトがわかりません。しかし、SelectedItem 自体が null に等しいかどうかを尋ねられる気がします。その場合、コードは次のようになります。

<DataTrigger Binding="{Binding RelativeSource={RelativeSource Self}, Path=SelectedItem}" Value="{x:Null}">
                <Setter Property="ComboBox.BorderBrush" Value="{StaticResource FaultyBorderBrush}" />
                <Setter Property="ComboBox.ToolTip" Value="Input value is mandatory" />
            </DataTrigger>

「内容」は不要です。

これはあなたが望んでいたものですか?

于 2012-11-20T10:09:59.560 に答える