4

我有一个停靠在停靠面板右侧的选项卡控件。选项卡控件的宽度设置为 10,不透明度设置为 0。当我将鼠标移到它上面时,我希望选项卡控件的宽度更改为 200,不透明度设置为 100。然后,当我将鼠标移开时,让选项卡控件返回其原始值。我不知道该怎么做。有人可以帮忙吗?下面是我的标记,我试图让选项卡控件首先显示。

<UserControl x:Class="Cordata.Mrs.MVVM.Views.Controls.SlideoutView"
         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">
<UserControl.Resources>
    <Storyboard x:Key="OnMouseEnter1">
        <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.Width)" Storyboard.TargetName="OptionsSlideout">
            <EasingDoubleKeyFrame KeyTime="0" Value="200"/>
        </DoubleAnimationUsingKeyFrames>
    </Storyboard>
</UserControl.Resources>
<UserControl.Triggers>
    <EventTrigger RoutedEvent="Mouse.MouseEnter">
        <BeginStoryboard Storyboard="{StaticResource OnMouseEnter1}"/>
    </EventTrigger>
</UserControl.Triggers>
<DockPanel HorizontalAlignment="Stretch">
    <TabControl Name="OptionsSlideout" TabStripPlacement="Bottom" Width="10" Margin="0,0,0,5" HorizontalAlignment="Stretch" DockPanel.Dock="Right" Opacity="0">
        <TabItem Header="Configure">
            <StackPanel Orientation="Vertical">
                <Button Name="ConfigurationBuilderButton" Width="80" Cursor="Hand" Click="ConfigurationBuilderButton_Click">
                    <Button.Template>
                        <ControlTemplate TargetType="Button">
                            <StackPanel>
                                <Image Source="/Images/ConfigurationBuilder.png" ToolTip="Run Configuration Builder" />
                                <TextBlock Text="Configuration Builder" TextWrapping="Wrap" FontWeight="Bold" />
                            </StackPanel>
                        </ControlTemplate>
                    </Button.Template>
                </Button>
                <Button Name="LoadConfigurationButton" Width="80" Cursor="Hand" Margin="0,20,0,0" Click="LoadConfigurationButton_Click">
                    <Button.Template>
                        <ControlTemplate TargetType="Button">
                            <StackPanel>
                                <Image Source="/Images/LoadCustomConfiguration.png" ToolTip="Load Custom Configuration" />
                                <TextBlock Text="Load Configuration" TextWrapping="Wrap" FontWeight="Bold" />
                            </StackPanel>
                        </ControlTemplate>
                    </Button.Template>
                </Button>
            </StackPanel>
        </TabItem>
        <TabItem Header="Help">
            <TextBlock Text="Help" />
        </TabItem>
    </TabControl>
</DockPanel>
</UserControl>
4

1 回答 1

5

我需要添加一个Rectangle以便DockPanel可以有一些主要内容,因此允许我们将您停靠TabControl在右侧。你不需要你的任何东西来做Resources这件事和另一件事......我不得不删除你的处理程序,因为我没有在我的测试项目中实现它们。无论如何,这将做你想做的事,只需TriggerIsMouseOver属性上使用 a :

<DockPanel HorizontalAlignment="Stretch">
    <TabControl Name="OptionsSlideout" TabStripPlacement="Bottom" Width="10" Margin="0,0,0,5" DockPanel.Dock="Right" Opacity="0.0">
        <TabControl.Style>
            <Style>
                <Style.Triggers>
                    <Trigger Property="Control.IsMouseOver" Value="True">
                        <Trigger.EnterActions>
                            <StopStoryboard BeginStoryboardName="CloseStoryBoard" />
                            <BeginStoryboard Name="OpenStoryBoard">
                                <Storyboard DecelerationRatio="0.8">
                                    <DoubleAnimation Storyboard.TargetProperty="(FrameworkElement.Width)" To="200.0" />
                                    <DoubleAnimation Storyboard.TargetProperty="Opacity" To="1.0" />
                                </Storyboard>
                            </BeginStoryboard>
                        </Trigger.EnterActions>
                        <Trigger.ExitActions>
                            <StopStoryboard BeginStoryboardName="OpenStoryBoard" />
                            <BeginStoryboard Name="CloseStoryBoard">
                                <Storyboard DecelerationRatio="0.8">
                                    <DoubleAnimation Storyboard.TargetProperty="(FrameworkElement.Width)" To="10.0" />
                                    <DoubleAnimation Storyboard.TargetProperty="Opacity" To="0.0" />
                                </Storyboard>
                            </BeginStoryboard>
                        </Trigger.ExitActions>
                    </Trigger>
                </Style.Triggers>
            </Style>
        </TabControl.Style>
        <TabItem Header="Configure">
            <StackPanel Orientation="Vertical">
                <Button Name="ConfigurationBuilderButton" Width="80" Cursor="Hand">
                    <Button.Template>
                        <ControlTemplate TargetType="Button">
                            <StackPanel>
                                <Image Source="/Images/ConfigurationBuilder.png" ToolTip="Run Configuration Builder" />
                                <TextBlock Text="Configuration Builder" TextWrapping="Wrap" FontWeight="Bold" />
                            </StackPanel>
                        </ControlTemplate>
                    </Button.Template>
                </Button>
                <Button Name="LoadConfigurationButton" Width="80" Cursor="Hand" Margin="0,20,0,0">
                    <Button.Template>
                        <ControlTemplate TargetType="Button">
                            <StackPanel>
                                <Image Source="/Images/LoadCustomConfiguration.png" ToolTip="Load Custom Configuration" />
                                <TextBlock Text="Load Configuration" TextWrapping="Wrap" FontWeight="Bold" />
                            </StackPanel>
                        </ControlTemplate>
                    </Button.Template>
                </Button>
            </StackPanel>
        </TabItem>
        <TabItem Header="Help">
            <TextBlock Text="Help" />
        </TabItem>
    </TabControl>
    <Rectangle Name="DummyContent" Fill="White" />
</DockPanel>

供将来参考 Mike,这里放的代码有点多。如果您刚刚使用了彩色RectangleBorder元素并说我想对此进行动画处理,那么用户会更容易将您的问题可视化Border。这样,缺少处理程序、图像Style和/或Resources元素不会减慢试图帮助您的用户的速度。在发布之前简化您的问题总是好的,有时,您甚至最终解决了自己的问题。无论如何,这不是问题,并且该代码可以满足您的要求。

于 2013-11-12T21:42:30.717 回答