如何为网格背景而不是网格中的控件设置图像的不透明度动画?

狄奥多西·冯·里奇霍芬

我希望我的背景图像为不透明度设置动画,但不希望其顶部的控件“覆盖”。这是我正在使用的XAML,但是当前控件(组合框等)也随图像淡入淡出。我如何更改它,以使控件也不会更改?

<Window x:Class="george.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="MainWindow" Height="350" Width="525" >
<Grid>
    <Grid.RowDefinitions>
        <RowDefinition />
        <RowDefinition />
    </Grid.RowDefinitions>
    <Border>
        <Border.Style>
            <Style TargetType="Border">
                <Setter Property="Background">
                    <Setter.Value>
                        <ImageBrush ImageSource="/George_mcfly.jpg" />
                    </Setter.Value>
                </Setter>
                <Setter Property="Opacity" Value="0.4" />
                <Style.Triggers>
                    <EventTrigger RoutedEvent="Border.MouseEnter">
                        <BeginStoryboard>
                            <Storyboard>
                                <DoubleAnimation To="0.8" AutoReverse="True" RepeatBehavior="Forever" Storyboard.TargetProperty="Opacity"></DoubleAnimation>
                            </Storyboard>
                        </BeginStoryboard>
                    </EventTrigger>
                    <EventTrigger RoutedEvent="Border.MouseLeave">
                        <BeginStoryboard>
                            <Storyboard>
                                <DoubleAnimation To="0.3"  AutoReverse="True" RepeatBehavior="Forever" Storyboard.TargetProperty="Opacity"></DoubleAnimation>
                            </Storyboard>
                        </BeginStoryboard>
                    </EventTrigger>

                </Style.Triggers>
            </Style>
        </Border.Style>
        <Grid Grid.Row="0">
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="60"/>
                <RowDefinition Height="60"/>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="Auto" />
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition />
                <ColumnDefinition />
            </Grid.ColumnDefinitions>
            <Label Content="{Binding ApplicationName}" FontSize="18" Grid.ColumnSpan="2" />
            <Label Content="Version:" Grid.Row="1" FontWeight="Bold" FontSize="14"/>
            <Label Content="{Binding Version}" FontSize="14" Foreground="Red" Grid.Row="1" Grid.Column="1"/>

            <Label Content="Current Connection:" Grid.Row="2" FontWeight="Bold"/>
            <Label Content="example" Grid.Row="2" Grid.Column="1"/>

            <ComboBox Grid.Row="3">
                <ComboBoxItem Content="A" />
                <ComboBoxItem Content="B" />
            </ComboBox>
            <Label Content="User Name: " Grid.Row="4" FontWeight="Bold"/>
            <Label Content="sample text" Grid.Row="4" Grid.Column="1"/>

            <Label Content="Active Directory Groups: " Grid.Row="5" FontWeight="Bold"/>
            <ListBox  Grid.Row="5" Grid.Column="1" Background="Transparent" BorderBrush="Transparent">
                <ListBoxItem Content="1" />
                <ListBoxItem Content="2" />
                <ListBoxItem Content="3" />
                <ListBoxItem Content="4" />
            </ListBox>
        </Grid>
    </Border>
</Grid>

克里斯·W

只需分离该父子关系即可,这非常简单,因为您已经将其嵌入到Grid中了;

    <Window x:Class="george.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525" >
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition />
            <RowDefinition />
        </Grid.RowDefinitions>
        <Border>
            <Border.Style>
                <Style TargetType="Border">
                    <Setter Property="Background">
                        <Setter.Value>
                            <ImageBrush ImageSource="/George_mcfly.jpg" />
                        </Setter.Value>
                    </Setter>
                    <Setter Property="Opacity" Value="0.4" />
                    <Style.Triggers>
                        <EventTrigger RoutedEvent="Border.MouseEnter">
                            <BeginStoryboard>
                                <Storyboard>
                                    <DoubleAnimation To="0.8" AutoReverse="True" RepeatBehavior="Forever" Storyboard.TargetProperty="Opacity"></DoubleAnimation>
                                </Storyboard>
                            </BeginStoryboard>
                        </EventTrigger>
                        <EventTrigger RoutedEvent="Border.MouseLeave">
                            <BeginStoryboard>
                                <Storyboard>
                                    <DoubleAnimation To="0.3"  AutoReverse="True" RepeatBehavior="Forever" Storyboard.TargetProperty="Opacity"></DoubleAnimation>
                                </Storyboard>
                            </BeginStoryboard>
                        </EventTrigger>
                    </Style.Triggers>
                </Style>
            </Border.Style>
<!-- We end the Border so it's only behind the elements instead of acting as their parent -->
            </Border>
            <Grid Grid.Row="0">
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="60"/>
                    <RowDefinition Height="60"/>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto" />
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition />
                    <ColumnDefinition />
                </Grid.ColumnDefinitions>
                <Label Content="{Binding ApplicationName}" FontSize="18" Grid.ColumnSpan="2" />
                <Label Content="Version:" Grid.Row="1" FontWeight="Bold" FontSize="14"/>
                <Label Content="{Binding Version}" FontSize="14" Foreground="Red" Grid.Row="1" Grid.Column="1"/>

                <Label Content="Current Connection:" Grid.Row="2" FontWeight="Bold"/>
                <Label Content="example" Grid.Row="2" Grid.Column="1"/>

                <ComboBox Grid.Row="3">
                    <ComboBoxItem Content="A" />
                    <ComboBoxItem Content="B" />
                </ComboBox>
                <Label Content="User Name: " Grid.Row="4" FontWeight="Bold"/>
                <Label Content="sample text" Grid.Row="4" Grid.Column="1"/>

                <Label Content="Active Directory Groups: " Grid.Row="5" FontWeight="Bold"/>
                <ListBox  Grid.Row="5" Grid.Column="1" Background="Transparent" BorderBrush="Transparent">
                    <ListBoxItem Content="1" />
                    <ListBoxItem Content="2" />
                    <ListBoxItem Content="3" />
                    <ListBoxItem Content="4" />
                </ListBox>
            </Grid>

    </Grid>

哦,McFly +1了,Marty和医生在哪里?:)

哦,而且,您可能会考虑将这些事件附加到父网格,并在动画中仅将边框定为目标,因为TargetNameTargetObject既然如此,则只有边框会定做。

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

设置窗口图像背景的不透明度属性

来自分类Dev

如何为图像创建不透明度

来自分类Dev

设置WPF标签内容Alpha透明度而不是整个控件的不透明度

来自分类Dev

OpenGL ES 2.0,如何为纹理的不透明度设置动画

来自分类Dev

如何为 IE 设置边框不透明度?

来自分类Dev

如何设置图像与DIV对应的不透明度

来自分类Dev

如何设置跨度背景(而不是文本)的不透明度?

来自分类Dev

如何设置跨度背景(而不是文本)的不透明度?

来自分类Dev

如何设置身体背景的图像不透明度

来自分类Dev

如何使用CSS为div的背景图像设置不透明度或降低亮度

来自分类Dev

如何使用CSS设置背景图像的不透明度?

来自分类Dev

如何在Xamarin.Forms中设置不透明度动画

来自分类Dev

改变网格不透明度的内存不足

来自分类Dev

如何使用Magick ++将具有透明背景的png图像设置为不透明度

来自分类Dev

如何在 C# 中使用滑块值更改网格不透明度

来自分类Dev

JavaFX 8中3D模型和网格的不透明度

来自分类Dev

背景图像不透明度问题

来自分类Dev

背景图像不透明度问题

来自分类Dev

jQuery设置CSS背景不透明度

来自分类Dev

使用插件将所有背景图像的不透明度设置为0

来自分类Dev

我们是否可以设置面板背景图像的不透明度?

来自分类Dev

Rmagick在水印中设置透明度不透明

来自分类Dev

使用DoubleAnimation设置图像不透明度

来自分类Dev

使用DoubleAnimation设置图像不透明度

来自分类Dev

多个CSS 3背景图像-在顶部图像中添加不透明度

来自分类Dev

如何Xamarin.Forms动画不透明度

来自分类Dev

在QML中创建不透明度动画

来自分类Dev

在QML中创建不透明度动画

来自分类Dev

SVG - 动画不透明度

Related 相关文章

热门标签

归档