Wpf 如何为网格背景而不是网格中的控件设置图像不透明度的动画?
我希望我的背景图像动画不透明度,但不是控制“覆盖”在它上面。这是我正在使用的XAML,但目前控件(组合框等)也随着图像淡入淡出。如何更改它,使控件也不更改Wpf 如何为网格背景而不是网格中的控件设置图像不透明度的动画?,wpf,xaml,Wpf,Xaml,我希望我的背景图像动画不透明度,但不是控制“覆盖”在它上面。这是我正在使用的XAML,但目前控件(组合框等)也随着图像淡入淡出。如何更改它,使控件也不更改 <Window x:Class="george.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/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>
只需分离父子关系,这非常简单,因为您已经将其嵌入到网格中
<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>
哦,麦克弗利的+1,马蒂和医生在哪里?:)
哦,还有,你可以考虑将这些事件附加到父网格中,并用<代码>目标名称< /代码>或<代码> TestObjult<代码>来定位动画中的边框。因为现在,只有边框才会这样做。
DOC以前是2个版本,罗琳是当前版本。我还没找到马蒂。我正在尝试你的建议,谢谢…lol BiFF是测试版。(账单信息和财务预测)。我必须记住在即将发布的时间表中添加针,谢谢!