使用淡入淡出动画使分组框出现和消失

发布于 2024-12-31 23:52:35 字数 5261 浏览 5 评论 0原文

在下面的示例中,我不明白如何在选中/取消选中上方复选框时使“实时更新”组框出现/消失。我正在 XAML 中寻找快速淡入/淡出效果,但我有点迷失..

在此处输入图像描述

<UserControl
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    x:Class="WpfControlLibrary1.MainControl"
    x:Name="MultiVol" MinHeight="520.12" MinWidth="213">

    <Grid HorizontalAlignment="Stretch">
        <Grid.Background>
                <LinearGradientBrush EndPoint="0.5,1" MappingMode="RelativeToBoundingBox" StartPoint="0.5,0">
                    <GradientStop Color="White" Offset="0.966"/>
                    <GradientStop Color="#FFD7D4FF"/>
                </LinearGradientBrush>
        </Grid.Background>

        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition />
        </Grid.ColumnDefinitions>

        <StackPanel x:Name="LayoutRoot" HorizontalAlignment="Stretch"  Grid.Row="0">

            <GroupBox Margin="8,0" BorderBrush="#FF88B1D8" HorizontalAlignment="Stretch" Height="99">
                <GroupBox.Header>
                    <WrapPanel>
                    <Label Content="General" Background="#00000000" Foreground="#FF0033FF" FontWeight="Bold" FontFamily="/WpfControlLibrary1;component/Fonts/#Tahoma" />    
                    </WrapPanel>
                </GroupBox.Header>

                <UniformGrid Columns="2">
                    <Label Content="RICs" />
                    <TextBox AcceptsReturn="False" AcceptsTab="True" AllowDrop="True" IsTabStop="True" />
                    <Label Content="Preference" />
                    <UniformGrid VerticalAlignment="Center" Columns="2" Rows="1">
                        <RadioButton GroupName="preference" Content="Exotic" IsChecked="False" />
                        <RadioButton GroupName="preference" Content="Flow" IsChecked="True" />
                    </UniformGrid>
                    <Label Content="Live updates" />
                    <CheckBox IsChecked="True" VerticalAlignment="Center"/>
                </UniformGrid>  
            </GroupBox>
        </StackPanel>

        <DockPanel Grid.Row="1" HorizontalAlignment="Stretch">
            <GroupBox Margin="8,0" BorderBrush="#FF88B1D8" HorizontalAlignment="Stretch">
                <GroupBox.Header>
                    <WrapPanel>
                    <Label Content="Live updates" Background="#00000000" Foreground="#FF0033FF" FontWeight="Bold" FontFamily="/WpfControlLibrary1;component/Fonts/#Tahoma" />   
                    </WrapPanel>
                </GroupBox.Header>
                    <ListView MinHeight="100" Background="{x:Null}">
                        <ListView.View>
                            <GridView AllowsColumnReorder="False">
                                <GridViewColumn Header="RIC" />
                                <GridViewColumn Header="Last tick" />
                           </GridView>
                        </ListView.View>
                    </ListView>
            </GroupBox>         
        </DockPanel>

        </Grid>
</UserControl>

更新:我现在淡入了,我尝试通过添加触发器标签来添加淡出:

           <DockPanel.Style>
                <Style TargetType="{x:Type DockPanel}">
                    <Style.Triggers>
                        <Trigger Property="Visibility" Value="Visible">
                            <Trigger.EnterActions>
                                <BeginStoryboard>
                                    <Storyboard>
                                        <DoubleAnimation Storyboard.TargetProperty="Opacity" Duration="00:00:0.5" From="0.0" To="1.0" />
                                    </Storyboard>
                                </BeginStoryboard>
                            </Trigger.EnterActions>
                        </Trigger>
                        <Trigger Property="Visibility" Value="Hidden">
                            <Trigger.EnterActions>
                                <BeginStoryboard>
                                    <Storyboard>
                                        <DoubleAnimation Storyboard.TargetProperty="Opacity" Duration="00:00:0.5" From="1.0" To="0.0" />
                                    </Storyboard>
                                </BeginStoryboard>
                            </Trigger.EnterActions>
                        </Trigger>
                    </Style.Triggers>
                </Style>
            </DockPanel.Style>

in the following example, I don't understand how I could make my "Live Updates" groupbox appear/disappear when the upper checkbox is checked/unchecked. I am looking for a fast fade in/fade out effect in XAML but I am a little lost..

enter image description here

<UserControl
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    x:Class="WpfControlLibrary1.MainControl"
    x:Name="MultiVol" MinHeight="520.12" MinWidth="213">

    <Grid HorizontalAlignment="Stretch">
        <Grid.Background>
                <LinearGradientBrush EndPoint="0.5,1" MappingMode="RelativeToBoundingBox" StartPoint="0.5,0">
                    <GradientStop Color="White" Offset="0.966"/>
                    <GradientStop Color="#FFD7D4FF"/>
                </LinearGradientBrush>
        </Grid.Background>

        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition />
        </Grid.ColumnDefinitions>

        <StackPanel x:Name="LayoutRoot" HorizontalAlignment="Stretch"  Grid.Row="0">

            <GroupBox Margin="8,0" BorderBrush="#FF88B1D8" HorizontalAlignment="Stretch" Height="99">
                <GroupBox.Header>
                    <WrapPanel>
                    <Label Content="General" Background="#00000000" Foreground="#FF0033FF" FontWeight="Bold" FontFamily="/WpfControlLibrary1;component/Fonts/#Tahoma" />    
                    </WrapPanel>
                </GroupBox.Header>

                <UniformGrid Columns="2">
                    <Label Content="RICs" />
                    <TextBox AcceptsReturn="False" AcceptsTab="True" AllowDrop="True" IsTabStop="True" />
                    <Label Content="Preference" />
                    <UniformGrid VerticalAlignment="Center" Columns="2" Rows="1">
                        <RadioButton GroupName="preference" Content="Exotic" IsChecked="False" />
                        <RadioButton GroupName="preference" Content="Flow" IsChecked="True" />
                    </UniformGrid>
                    <Label Content="Live updates" />
                    <CheckBox IsChecked="True" VerticalAlignment="Center"/>
                </UniformGrid>  
            </GroupBox>
        </StackPanel>

        <DockPanel Grid.Row="1" HorizontalAlignment="Stretch">
            <GroupBox Margin="8,0" BorderBrush="#FF88B1D8" HorizontalAlignment="Stretch">
                <GroupBox.Header>
                    <WrapPanel>
                    <Label Content="Live updates" Background="#00000000" Foreground="#FF0033FF" FontWeight="Bold" FontFamily="/WpfControlLibrary1;component/Fonts/#Tahoma" />   
                    </WrapPanel>
                </GroupBox.Header>
                    <ListView MinHeight="100" Background="{x:Null}">
                        <ListView.View>
                            <GridView AllowsColumnReorder="False">
                                <GridViewColumn Header="RIC" />
                                <GridViewColumn Header="Last tick" />
                           </GridView>
                        </ListView.View>
                    </ListView>
            </GroupBox>         
        </DockPanel>

        </Grid>
</UserControl>

UPDATE : I get the fade in now, and I tried to add the fade out by adding a Trigger tag :

           <DockPanel.Style>
                <Style TargetType="{x:Type DockPanel}">
                    <Style.Triggers>
                        <Trigger Property="Visibility" Value="Visible">
                            <Trigger.EnterActions>
                                <BeginStoryboard>
                                    <Storyboard>
                                        <DoubleAnimation Storyboard.TargetProperty="Opacity" Duration="00:00:0.5" From="0.0" To="1.0" />
                                    </Storyboard>
                                </BeginStoryboard>
                            </Trigger.EnterActions>
                        </Trigger>
                        <Trigger Property="Visibility" Value="Hidden">
                            <Trigger.EnterActions>
                                <BeginStoryboard>
                                    <Storyboard>
                                        <DoubleAnimation Storyboard.TargetProperty="Opacity" Duration="00:00:0.5" From="1.0" To="0.0" />
                                    </Storyboard>
                                </BeginStoryboard>
                            </Trigger.EnterActions>
                        </Trigger>
                    </Style.Triggers>
                </Style>
            </DockPanel.Style>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

依 靠 2025-01-07 23:52:35

两步。
首先Visibility

  • 在资源中创建一个BooleanToVisibilityConverter

    ;
        >
    
    
  • 为您的 CheckBox 命名

    
    
  • 使用 BooleanToVisibilityConverter 为每个 ElementName 绑定 DockPanel.Visibility 属性

    
    

第二个 Animation

  • 创建一个 LiveUpdates DockPanel 的 DockPanel.Style

    
        
        
    
    

Two steps.
First Visibility:

  • Create a BooleanToVisibilityConverter in Resources

    <UserControl.Resources>
        <BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter" />
    </UserControl.Resources>
    
  • Give your CheckBox a name

    <CheckBox x:Name="LiveUpdateCheckBox" IsChecked="True" VerticalAlignment="Center" />
    
  • Bind the DockPanel.Visibility property per ElementName with BooleanToVisibilityConverter

    <DockPanel Grid.Row="1" HorizontalAlignment="Stretch"
               Visibility="{Binding ElementName=LiveUpdateCheckBox, Path=IsChecked, Converter={StaticResource BooleanToVisibilityConverter}}">
    

Second Animation:

  • Create a DockPanel.Style for your LiveUpdates DockPanel

    <DockPanel.Style>
        <Style TargetType="{x:Type DockPanel}">
            <Style.Triggers>
                <Trigger Property="Visibility" Value="Visible">
                    <Trigger.EnterActions>
                        <BeginStoryboard>
                            <Storyboard>
                                <DoubleAnimation Storyboard.TargetProperty="Opacity" Duration="00:00:01" From="0.0" To="1.0" />
                            </Storyboard>
                        </BeginStoryboard>
                    </Trigger.EnterActions>
                </Trigger>
            </Style.Triggers>
        </Style>
    </DockPanel.Style>
    
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文