0

我有一个自定义 Wpf 控件,即combobox:WpfTwComboBox. 我想使用一个名为DisableProviderSelector.

通常使用触发器没有帮助。这里的场景是当上面的控件,即 WindowsFormsHost 可见或折叠时,我希望下面的自定义控件发生相反的情况。

<StackPanel Grid.Row="3" Grid.Column="2" Height="25" Orientation="Horizontal"     
            Width="375" HorizontalAlignment="Left">
    <WindowsFormsHost Height="25" Width="375">
        <WindowsFormsHost.Style>
            <Style TargetType="WindowsFormsHost">
                <Style.Triggers>
                    <DataTrigger Binding="{Binding Path=DisableProviderSelector}" Value="true">
                        <Setter Property="Visibility" Value="Collapsed"/>
                    </DataTrigger>
                    <DataTrigger Binding="{Binding Path=DisableProviderSelector}" Value="false">
                        <Setter Property="Visibility" Value="Visible"/>
                    </DataTrigger>
                </Style.Triggers>     
            </Style>
        </WindowsFormsHost.Style>
        <commonControls:ProviderSelectorControl RequiredLevel="Save" ModifiedByUser="providerSelectorControl1_ModifiedByUser" x:Name="providerSelectorControl1"/>
    </WindowsFormsHost>
    <combobox:WpfTwComboBox x:Name="PortalProviderSelector"
                            SelectedValue="{Binding SelectedPortalProvider}"
                            ItemsSource="{Binding Path=PortalProvidersCollection}" 
                            DisplayMemberPath="FullName" Width="350" Height="25"
                            RequiredLevelFlag="Save">
    </combobox:WpfTwComboBox>            
</StackPanel>

谁能帮我在这里设置可见性?

4

1 回答 1

1

DisableProviderSelector设置为 True 时的 bool 也需要WindowsFormsHostCollapsed并且ComboBox需要是Visible。当 bool 为假时反转。

因此,就 theComboBox而言,如果 bool 为 True ,则为VisibleFalse Collapsed。因此只需将ComboBox直接绑定到属性并使用BooleantoVisibilityConverter

xml:

<Window.Resources>
  <BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter" />
</Window.Resources>
...
<combobox:WpfTwComboBox x:Name="PortalProviderSelector"
                        Width="350"
                        Height="25"
                        DisplayMemberPath="FullName"
                        ItemsSource="{Binding Path=PortalProvidersCollection}"
                        RequiredLevelFlag="Save"
                        Visibility="{Binding DisableProviderSelector,
                                            Converter={StaticResource BooleanToVisibilityConverter}}"
                        SelectedValue="{Binding SelectedPortalProvider}" />
于 2013-05-04T16:09:56.170 回答