隐藏并显示放置在usercontrol中的usercontrol

时间:2015-07-16 11:02:05

标签: c# wpf

我有两个用户控件(A& B)放在特定的用户控件(C)上。我希望这些控件只在单击按钮时出现或显示。我将A和B控件的可见性绑定到属性但没有用。我也将样式应用于隐藏/显示但是再次没有成功。

此外,如果A和B控件都不可见,我希望拉伸usercontrol C. 这是usercontrol xaml,其中main datacontext是RunViewModelObject

<UserControl>
<UserControl.Resources>
        <Style TargetType="{x:Type Control}" x:Key="RTMLOVPanel">
            <Setter Property="Visibility" Value="Hidden" />
            <Style.Triggers>
                <DataTrigger Binding="{Binding LovPaneVisible, ElementName=RtmLovView, Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" Value="true">
                    <Setter Property="Visibility" Value="Visible" />
                </DataTrigger>
            </Style.Triggers>
        </Style>

        <Style TargetType="{x:Type Control}" x:Key="AttachmentPanel">
            <Setter Property="Visibility" Value="Hidden" />
            <Style.Triggers>
                <DataTrigger Binding="{Binding AttachmentsPaneVisible, ElementName=AttachmentsView, Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" Value="true">
                    <Setter Property="Visibility" Value="Visible" />
                </DataTrigger>
            </Style.Triggers>
        </Style>

        <ControlTemplate x:Key="RtmLovTemplate" x:Name="RtmLovView">
            <Shared:SidePaneView_RtmLov/>
        </ControlTemplate>

        <ControlTemplate x:Key="AttachmentsTemplate" x:Name="AttachmentsView">
            <Shared:SidePaneView_Attachments/>
        </ControlTemplate>

    </UserControl.Resources>
    <Grid DataContext="{Binding RunViewModelObject}">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto" />
            <ColumnDefinition Width="*"/>
        </Grid.ColumnDefinitions>

        <ContentControl Grid.Column="0" Template="{StaticResource ResourceKey=RtmLovTemplate}" 
                DataContext="{Binding LovObject}" Style="{DynamicResource RTMLOVPanel}" />

        <ContentControl Grid.Column="0" Template="{StaticResource ResourceKey=AttachmentsTemplate}"
                DataContext="{Binding AttachmentsObject}" Style="{DynamicResource AttachmentPanel}" />

        <Grid Grid.Column="1"  >
            <ContentControl x:Name="CCRunView" Loaded="UserControl_Loaded" Unloaded="UserControl_Unloaded" >                
                <ContentControl.Content>
                    <UC:UCDynamicRunForm Visibility="{Binding DataSourceControlVisibility, Converter={StaticResource ResourceKey=BoolToOppositeVisibilityConverter}}" DataContext="{Binding UCDynamicFormVMObject}"/>
                </ContentControl.Content>
            </ContentControl>
        </Grid>
    </Grid>
</UserControl>

0 个答案:

没有答案