2

在我的主页上,我有一个扩展器,它有一个用于动画的事件触发器,如下所示:

            <StackPanel.Triggers>
                <EventTrigger RoutedEvent="Expander.Expanded" SourceName="expander">
                    <EventTrigger.Actions>
                        <BeginStoryboard>
                            <Storyboard>
                                <DoubleAnimation From="0" To="1.2" Duration="0:0:0.35" Storyboard.TargetName="content1" Storyboard.TargetProperty="(FrameworkElement.LayoutTransform).(ScaleTransform.ScaleX)" AutoReverse="False" />
                            </Storyboard>
                        </BeginStoryboard>
                    </EventTrigger.Actions>
                </EventTrigger>
            </StackPanel.Triggers>

            <Expander x:Name="expander" ExpandDirection="Right" OpacityMask="#6C806969" Background="#FF807171" >
            <Grid x:Name="content1" Background="#FF807171" Width="378"> 
                ......user control inside here                      
                    <Grid.LayoutTransform>
                    <ScaleTransform ScaleX="0" ScaleY="1"/>
                </Grid.LayoutTransform>
            </Grid>
        </Expander>

这只是将扩展器缓慢滑出。但是在一个扩展器标题区域内,我有另一个扩展器(一个垂直设置,另一个水平设置。

水平扩展器是 UserControl 的一部分。当我扩展这个扩展器时,它也会从主窗口中触发垂直扩展器。

<UserControl x:Class="WpfApplication4.AppPages.AddPost"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             mc:Ignorable="d" 
             d:DesignHeight="464" d:DesignWidth="416">
    <Expander Header="expander1" Height="441" HorizontalAlignment="Left" Margin="10,10,0,0" VerticalAlignment="Top">
    ..... some content
    </Expander> 

有没有办法阻止这种情况发生?

4

1 回答 1

1

这是我评论中建议的示例代码:

<Expander x:Name="expander" ExpandDirection="Right" OpacityMask="#6C806969" Background="#FF807171">

    ... Content ...

    <Expander.Style>
        <Style TargetType="{x:Type Expander}">
            <Setter Property="LayoutTransform">
                <Setter.Value>
                    <ScaleTransform ScaleX="1" />
                </Setter.Value>
            </Setter>
            <Style.Triggers>
                <Trigger Property="IsExpanded" Value="True">
                    <Trigger.EnterActions>
                        <BeginStoryboard>
                            <Storyboard>
                                <DoubleAnimation From="0" To="1.2" Duration="0:0:0.35" AutoReverse="False"
                                                 Storyboard.TargetProperty="LayoutTransform.(ScaleTransform.ScaleX)" />
                            </Storyboard>
                        </BeginStoryboard>
                    </Trigger.EnterActions>
                </Trigger>       
            </Style.Triggers>
        </Style>
    </Expander.Style>
</Expander>
于 2012-04-20T17:25:37.730 回答