2013-05-04 39 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}" /> 
相關問題