尝试在WPF应用程序中更改属性时开始情节提要
我有一个简单的MVVM应用程序。它包含一个属性,当一个方法正确执行时,我会将该属性更改为true,如果现在正确执行,则更改为false。当这个属性改变时,我想在WPF应用程序的状态栏上显示“通过”或“失败”,然后让它消失几秒钟 所以我读过StackOverflow,并在谷歌上搜索了很多,但都没有结果。我想我误解了我需要如何构建故事板尝试在WPF应用程序中更改属性时开始情节提要,wpf,xaml,animation,properties,storyboard,Wpf,Xaml,Animation,Properties,Storyboard,我有一个简单的MVVM应用程序。它包含一个属性,当一个方法正确执行时,我会将该属性更改为true,如果现在正确执行,则更改为false。当这个属性改变时,我想在WPF应用程序的状态栏上显示“通过”或“失败”,然后让它消失几秒钟 所以我读过StackOverflow,并在谷歌上搜索了很多,但都没有结果。我想我误解了我需要如何构建故事板 <Grid> <Grid.DataContext> <WpfApplication1:MainViewMode
<Grid>
<Grid.DataContext>
<WpfApplication1:MainViewModel/>
</Grid.DataContext>
<Grid.Resources>
<Style x:Key="statusStyle" TargetType="StatusBar">
<Setter Property="Opacity" Value="0"/>
<Style.Triggers>
<DataTrigger Binding="{Binding Pulse}" Value="True">
<DataTrigger.EnterActions>
<BeginStoryboard>
<Storyboard>
<DoubleAnimationUsingKeyFrames
AutoReverse="True"
Storyboard.TargetProperty="(UIElement.Opacity)" >
<EasingDoubleKeyFrame KeyTime="0" Value="0"/>
<EasingDoubleKeyFrame KeyTime="0:0:0.5" Value="1"/>
<EasingDoubleKeyFrame KeyTime="0:0:3" Value="1"/>
<EasingDoubleKeyFrame KeyTime="0:0:4" Value="0"/>
</DoubleAnimationUsingKeyFrames>
</Storyboard>
</BeginStoryboard>
</DataTrigger.EnterActions>
</DataTrigger>
</Style.Triggers>
</Style>
</Grid.Resources>
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition Height="auto"/>
</Grid.RowDefinitions>
<StatusBar Style="{StaticResource statusStyle}"
Grid.Row="1" ItemsSource="{Binding Items}" />
<CheckBox Content="CheckBox" Height="16"
HorizontalAlignment="Left" Margin="41,30,0,0"
IsChecked="{Binding Pulse}" VerticalAlignment="Top" />
</Grid>
在我的状态栏中,我添加了一个故事板,我正试图在XAML文件开头的
中触发它。这是正确的吗?目前我使用的是0/1的虚拟值,我认为正确的做法是使用我可以制作的BooleantString转换器,或者有更好的方法
因此,我的状态栏包含:
<StatusBar >
<StatusBar.Resources>
<Storyboard x:Key="StatusBar" >
<DoubleAnimationUsingKeyFrames
Storyboard.TargetProperty="(UIElement.Opacity)"
Storyboard.TargetName="statusBarItem">
<EasingDoubleKeyFrame KeyTime="0" Value="0"/>
<EasingDoubleKeyFrame KeyTime="0:0:0.5" Value="1"/>
<EasingDoubleKeyFrame KeyTime="0:0:3" Value="1"/>
<EasingDoubleKeyFrame KeyTime="0:0:4" Value="0"/>
</DoubleAnimationUsingKeyFrames>
</Storyboard>
</StatusBar.Resources>
</StatusBar>
任何帮助、资源或信息都将不胜感激。非常感谢。这里有一个例子。您需要使用触发器来启动故事板
<Grid>
<Grid.DataContext>
<WpfApplication1:MainViewModel/>
</Grid.DataContext>
<Grid.Resources>
<Style x:Key="statusStyle" TargetType="StatusBar">
<Setter Property="Opacity" Value="0"/>
<Style.Triggers>
<DataTrigger Binding="{Binding Pulse}" Value="True">
<DataTrigger.EnterActions>
<BeginStoryboard>
<Storyboard>
<DoubleAnimationUsingKeyFrames
AutoReverse="True"
Storyboard.TargetProperty="(UIElement.Opacity)" >
<EasingDoubleKeyFrame KeyTime="0" Value="0"/>
<EasingDoubleKeyFrame KeyTime="0:0:0.5" Value="1"/>
<EasingDoubleKeyFrame KeyTime="0:0:3" Value="1"/>
<EasingDoubleKeyFrame KeyTime="0:0:4" Value="0"/>
</DoubleAnimationUsingKeyFrames>
</Storyboard>
</BeginStoryboard>
</DataTrigger.EnterActions>
</DataTrigger>
</Style.Triggers>
</Style>
</Grid.Resources>
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition Height="auto"/>
</Grid.RowDefinitions>
<StatusBar Style="{StaticResource statusStyle}"
Grid.Row="1" ItemsSource="{Binding Items}" />
<CheckBox Content="CheckBox" Height="16"
HorizontalAlignment="Left" Margin="41,30,0,0"
IsChecked="{Binding Pulse}" VerticalAlignment="Top" />
</Grid>
视图模型
public class MainViewModel : ViewModelBase
{
private bool _pulse;
public MainViewModel()
{
Items = new[] {"Passed"};
}
public IList<string> Items { get; private set; }
public bool Pulse
{
get { return _pulse; }
set { Set(()=>Pulse, ref _pulse, value); }
}
}
public类MainViewModel:ViewModelBase
{
私用布尔脉冲;
公共主视图模型()
{
Items=new[]{“Passed”};
}
公共IList项{get;private set;}
公共布尔脉冲
{
获取{返回_脉冲;}
set{set(()=>Pulse,ref_Pulse,value);}
}
}
我在哪里可以找到ViewModelBase的实现?@Guge如果我记得那是MVVM light的话。在本例中,它所做的只是INotifyPropertyChanged的一个实现。