我希望我的背景图像为不透明度设置动画,但不希望其顶部的控件“覆盖”。这是我正在使用的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>
只需分离该父子关系即可,这非常简单,因为您已经将其嵌入到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和医生在哪里?:)
哦,而且,您可能会考虑将这些事件附加到父网格,并在动画中仅将边框定为目标,因为TargetName
或TargetObject
既然如此,则只有边框会定做。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句