/ / WPF - animacja DataTrigger nie działa - c #, wpf, animacja, datatrigger

WPF - Animacja DataTrigger nie działa - c #, wpf, animacja, datatrigger

Próbuję więc zrobić animacje podczas usuwania elementów z ItemsControl, który jest dołączony ObservableCollectio<Item> Wiem, że nie mogę tego zrobić w przypadku rozładowania, ponieważ po prostu jest za późno na wykonanie dowolnej animacji, więc próbowałem to zrobić za pomocą DataTrigger

Mój xaml plik wygląda następująco:

 <DataTemplate DataType="{x:Type MyApp:Item}">
<Border x:Name="ItemBorder">
<Label Content="{Binding Path=Name}" />
</Border>
<DataTemplate.Triggers>
<DataTrigger Binding="{Binding Path=Removing}" Value="True">
<DataTrigger.EnterActions>
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Duration="0:0:1" From="1.0" To="0.0"
Storyboard.TargetProperty="(Border.Opacity)" />
</Storyboard>
</BeginStoryboard>
</DataTrigger.EnterActions>
</DataTrigger>
</DataTemplate.Triggers>
</DataTemplate>

i mój Item klasa jest po prostu:

public class Item : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged = delegate { };

private bool removing;
public bool Removing {
get
{
return removing;
}
set
{
removing = value;
PropertyChanged(this, new PropertyChangedEventArgs("Removing"));
}
}

// same with `Name` property
}

Chciałbym rozpocząć animację od ustawienia item.Removing = true ale nic się nie dzieje.

Co ja robię źle?

Odpowiedzi:

6 dla odpowiedzi № 1

Będziesz musiał zaktualizować animację, jak poniżej, tzn. Podaj nazwę elementu:

              <DataTemplate.Triggers>
<DataTrigger Binding="{Binding Removing}" Value="True">
<DataTrigger.EnterActions>
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Duration="0:0:1" From="1.0" To="0.0"
Storyboard.TargetProperty="Opacity" Storyboard.TargetName="ItemBorder" />
</Storyboard>
</BeginStoryboard>
</DataTrigger.EnterActions>

</DataTrigger>
</DataTemplate.Triggers>

LUB

Spróbuj umieścić animację bezpośrednio na swoim stylu obramowania, jak poniżej:

<DataTemplate DataType="{x:Type MyApp:Item}">
<Border x:Name="ItemBorder">
<Label Content="{Binding Path=Name}" />
<Border.Style>
<Style TargetType="Border">
<Style.Triggers>
<DataTrigger Binding="{Binding Path=Removing}" Value="True">
<DataTrigger.EnterActions>
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Duration="0:0:1" From="1.0" To="0.0"
Storyboard.TargetProperty="Opacity" />
</Storyboard>
</BeginStoryboard>
</DataTrigger.EnterActions>
</DataTrigger>
<Style.Triggers>
</Style>
</DataTemplate>