2013-05-04 44 views
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> 

任何人都可以请帮助我如何设置可见性在这里?

回答

1

所以DisableProviderSelector是一个布尔值,当设置为True WindowsFormsHost需求为CollapsedComboBox需求为Visible。当bool为假时反转。

因此,就ComboBox而言,如果bool为True,则它是Visible,当False时它是Collapsed。因此,只需要直接绑定ComboBox的属性,并使用一个BooleantoVisibilityConverter

XAML:

<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}" /> 
相关问题