[英]DataTrigger storyboard not firing WPF on PropertyValueChange
因此,如果以前已經回答過這個問題,請提前原諒我,但我一生中一直看不到它,但是過去4個小時我一直無濟於事。
我正在嘗試讓DataTrigger在單個bool屬性的更改上觸發。 DataTrigger將開始一個故事板,只需調整窗口大小即可。
這是XAML:
<Window.Resources>
<local:SatisfactionsViewModel x:Key="SatisfactionsViewModel"/>
<!--The storyboard animation-->
<Storyboard x:Key="windowFadeUp">
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.Height)" Storyboard.TargetName="Satisfaction_Processing">
<EasingDoubleKeyFrame KeyTime="0:0:0.5" Value="171"/>
</DoubleAnimationUsingKeyFrames>
</Storyboard>
</Window.Resources>
<!--The Datatrigger that doesn't seem to work, probably my own stupidity-->
<Window.Style>
<Style>
<Style.Triggers>
<DataTrigger Binding="{Binding Path=IsWorkingOnStuff, NotifyOnSourceUpdated=True}" Value="true">
<DataTrigger.EnterActions>
<BeginStoryboard Storyboard="{StaticResource windowFadeUp}"/>
</DataTrigger.EnterActions>
</DataTrigger>
</Style.Triggers>
</Style>
</Window.Style>
這是ViewModel中的相關C#:
private bool isWorkingOnStuff;
public bool IsWorkingOnStuff
{
get { return isWorkingOnStuff; }
set
{
if (value == isWorkingOnStuff)
{ return; }
isWorkingOnStuff = value;
OnPropertyChanged();
}
}
//Other non-relative stuff
//PropertyChangedEvent handler
public event PropertyChangedEventHandler PropertyChanged;
private void OnPropertyChanged([CallerMemberName]string propertyName = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
//Bunch of other stuff not related
private void ProcessCommand()
{
if (fileName == null || fileName == "")
{
MessageBox.Show("Please select a file. \nIt won't work without one... -_-");
}
else
{
IsWorkingOnStuff = true;
IsProcessEnabled = false;
IsProgressBarVisibile = Visibility.Visible;
//more business logic goes here...
}
}
因此,據我了解,當IsWorkingOnStuff屬性更改為true時,數據觸發器應觸發,情節提要執行,並發生歡樂...但事實並非如此。
知道我要去哪里錯了嗎?
提前謝謝你。
刪除Storyboard.TargetName
屬性,並確保已將窗口的DataContext
設置為SatisfactionsViewModel
類的實例:
<Window x:Class="WpfApplication1.MainWindow"
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"
xmlns:local="clr-namespace:WpfApplication1"
mc:Ignorable="d"
Title="MainWindow" Height="300" Width="300" x:Name="Satisfaction_Processing">
<Window.DataContext>
<local:SatisfactionsViewModel />
</Window.DataContext>
<Window.Resources>
<!--The storyboard animation-->
<Storyboard x:Key="windowFadeUp">
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.Height)">
<EasingDoubleKeyFrame KeyTime="0:0:0.5" Value="171"/>
</DoubleAnimationUsingKeyFrames>
</Storyboard>
</Window.Resources>
<Window.Style>
<Style>
<Style.Triggers>
<DataTrigger Binding="{Binding Path=IsWorkingOnStuff, NotifyOnSourceUpdated=True}" Value="true">
<DataTrigger.EnterActions>
<BeginStoryboard Storyboard="{StaticResource windowFadeUp}"/>
</DataTrigger.EnterActions>
</DataTrigger>
</Style.Triggers>
</Style>
</Window.Style>
<StackPanel>
</StackPanel>
</Window>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.