如果txt为空,则WPF删除选定项

uz75evzq  于 2023-05-30  发布在  其他
关注(0)|答案(1)|浏览(206)

我禁用组合,如果文本是空的,但一旦我选择了cbo和删除文本从文本框,cbo选定的项目仍然可见

<TextBox Name="txt0"  PreviewTextInput="NumericOnly" HorizontalAlignment="Left" Height="23" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Width="70" Margin="52,83,0,0"/>
    <ComboBox Name="cbo0" ItemsSource="{Binding Source={StaticResource enumValues}}" HorizontalAlignment="Left"  VerticalAlignment="Top" Width="77" Margin="144,84,0,0">
        <ComboBox.Style>
            <Style TargetType="{x:Type ComboBox}">
                <Setter Property="IsEnabled" Value="True" />
                <Style.Triggers>
                    <DataTrigger Binding="{Binding ElementName=txt0, Path=Text}"  Value="">
                        <Setter Property="IsEnabled" Value="False" />
                    </DataTrigger>
                </Style.Triggers>
            </Style>
        </ComboBox.Style>
    </ComboBox>
sulc1iza

sulc1iza1#

我只需要加一个二传手

<DataTrigger Binding="{Binding ElementName=txt0, Path=Text}"  Value="">
                        <Setter  Property="IsEnabled" Value="False" />
                        <Setter  Property="SelectedIndex" Value="-1" />
                    </DataTrigger>

相关问题