Crash when animating ItemsControl through DataTriggers









up vote
0
down vote

favorite












Preface



I am writing a program that has a map class that contains a background image and list (ObservableCollection) of nodes that have colour, location and animation properties. A WPF application over the top has this referenced



Problem



I have an object of type GameMapModel that contains an observable collection of type GameMapNode:



 [AddINotifyPropertyChangedInterface]
public class GameMapModel

public ObservableCollection<GameMapNode> GameMapNodes get; set; = new ObservableCollection<GameMapNode>();
public GameMapNode SelectedNode get; set;
public BitmapImage Background get; set; = GameMap.jpg; //Link removed for forum post.


public GameMapModel()

//SelectedNode = new GameMapNode(0, 0, Brushes.White, "Default");



[AddINotifyPropertyChangedInterface]
public class GameMapNode

public int X get; set; = 0;
public int Y get; set; = 0;
public Brush Colour get; set; = Brushes.Gray;
public string Name get; set; = "Default";
public bool Pulse get; set; = false;
public bool Spin get; set; = false;
public bool Throb get; set; = false;
public bool Bounce get; set; = false;

public GameMapNode(int x, int y, Brush colour, String name)

X = x;
Y = y;
//Colour = colour;
Name = name;


public void ChangeTeam()

if (Colour == Brushes.Blue)

Colour = Brushes.Red;
Spin = true;
Bounce = true;
Pulse = true;
Throb = true;

else

Colour = Brushes.Blue;
Spin = false;
Bounce = false;
Pulse = false;
Throb = false;





I am then have a UserControl that renders the map background and nodes based on the contents of the GameMapModel:



 <Grid Grid.Column="1" Name="MapGrid" MouseMove="Grid_MouseMove" MouseUp="Grid_MouseUp" Width="Binding GameMap.Background.Width" Height="Binding GameMap.Background.Height" Background="Black">
<Image Source="Binding GameMap.Background" Stretch="Fill"/>

<ItemsControl ItemsSource="Binding GameMap.GameMapNodes">

<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<Canvas Name="MapCanvas" Width="Binding Background.Width" Height="Binding Background.Height" MinHeight="240" MinWidth="320" IsItemsHost="True"/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>

<ItemsControl.ItemContainerStyle>
<Style TargetType="ContentPresenter">
<Setter Property="Canvas.Left" Value="Binding X" />
<Setter Property="Canvas.Top" Value="Binding Y" />
<Setter Property="ContentTemplate">
<Setter.Value>
<DataTemplate>
<Grid>
<!-- <Rectangle x:Name="rect2" Stroke="Binding GameMap.Colour" StrokeThickness="20" Width="10" Height="10" /> -->

<Rectangle x:Name="rect1" Stroke="Binding Colour" MouseRightButtonDown="Rectangle_MouseRightButtonDown" MouseLeftButtonDown="Rectangle_MouseLeftButtonDown" StrokeThickness="20" Width="10" Height="10">

<Rectangle.RenderTransform>
<TransformGroup>
<RotateTransform x:Name="noFreeze" CenterX="5" CenterY="5"/>
<TranslateTransform x:Name="noFreeze2" />
<ScaleTransform x:Name="NoFreeze3" CenterX="5" CenterY="5"/>
</TransformGroup>
</Rectangle.RenderTransform>

<Rectangle.Style >
<Style TargetType="Rectangle" x:Name="RectangleStyle">
<Style.Triggers>

<DataTrigger Binding="Binding Pulse" Value="True" x:Name="PulseDataTrigger">
<DataTrigger.EnterActions>
<BeginStoryboard x:Name="PulseAnimation">
<Storyboard>
<DoubleAnimation Storyboard.TargetProperty="Opacity" To="0.5" Duration="0:0:1" RepeatBehavior="Forever" AutoReverse="True"/>
</Storyboard>
</BeginStoryboard>
</DataTrigger.EnterActions>
<DataTrigger.ExitActions>
<StopStoryboard BeginStoryboardName="PulseAnimation"/>
</DataTrigger.ExitActions>
</DataTrigger>

<DataTrigger Binding="Binding Spin" Value="True">
<DataTrigger.EnterActions>
<BeginStoryboard x:Name="SpinAnimation">
<Storyboard>
<DoubleAnimation Storyboard.TargetProperty="(Rectangle.RenderTransform).(TransformGroup.Children)[0].(RotateTransform.Angle)" To="-360" Duration="0:0:4" RepeatBehavior="Forever" />
</Storyboard>
</BeginStoryboard>
</DataTrigger.EnterActions>
<DataTrigger.ExitActions>
<StopStoryboard BeginStoryboardName="SpinAnimation"/>
</DataTrigger.ExitActions>
</DataTrigger>

<DataTrigger Binding="Binding Bounce" Value="True">
<DataTrigger.EnterActions>
<BeginStoryboard x:Name="BounceAnimation">
<Storyboard>
<DoubleAnimation Storyboard.TargetProperty="(Rectangle.RenderTransform).(TransformGroup.Children)[1].(TranslateTransform.Y)" From="5" To="-5" Duration="0:0:1" RepeatBehavior="Forever" AutoReverse="True"/>
</Storyboard>
</BeginStoryboard>
</DataTrigger.EnterActions>
<DataTrigger.ExitActions>
<StopStoryboard BeginStoryboardName="BounceAnimation"/>
</DataTrigger.ExitActions>
</DataTrigger>

<DataTrigger Binding="Binding Throb" Value="True">
<DataTrigger.EnterActions>
<BeginStoryboard x:Name="ThrobAnimation">
<Storyboard>
<DoubleAnimation Storyboard.TargetProperty="(Rectangle.RenderTransform).(TransformGroup.Children)[2].(ScaleTransform.ScaleX)" From="1" To="2" Duration="0:0:1" RepeatBehavior="Forever" AutoReverse="True"/>
<DoubleAnimation Storyboard.TargetProperty="(Rectangle.RenderTransform).(TransformGroup.Children)[2].(ScaleTransform.ScaleY)" From="1" To="2" Duration="0:0:1" RepeatBehavior="Forever" AutoReverse="True"/>
</Storyboard>
</BeginStoryboard>
</DataTrigger.EnterActions>
<DataTrigger.ExitActions>
<StopStoryboard BeginStoryboardName="ThrobAnimation"/>
</DataTrigger.ExitActions>
</DataTrigger>

</Style.Triggers>
</Style>
</Rectangle.Style>
</Rectangle>
</Grid>
</DataTemplate>
</Setter.Value>
</Setter>
</Style>
</ItemsControl.ItemContainerStyle>
</ItemsControl>
</Grid>


Now all this works fine IF Spin, Bounce and Throb are false when I create a new instance of GameMapNode and add to the collection, after that, I can set any and all to true and animations work as expected.



If I set any of those 3 to be true during object creation then I get the following error and the program crashes:




System.Windows.Markup.XamlParseException: ''[Unknown]' property does not point to a DependencyObject in path '(0).(1)[0].(2)'.'




If I comment out the Spin/Throb/Bounce DoubleAnimation blocks of the XAML, then the animations don't work, but the program doesn't crash.



The same is NOT true for the Opacity animation which works fine, even if Pulse is set to true during object creation.



This makes me think it's something to do with TransformGroup implementation as this is NOT used for the pulse. Maybe they're not loaded before the DataTrigger is first tried?



This is my first real WPF application and I have a great mentor helping me through it, but even he's stumped. Any help of suggestions would be greatly appreciated :)










share|improve this question

























    up vote
    0
    down vote

    favorite












    Preface



    I am writing a program that has a map class that contains a background image and list (ObservableCollection) of nodes that have colour, location and animation properties. A WPF application over the top has this referenced



    Problem



    I have an object of type GameMapModel that contains an observable collection of type GameMapNode:



     [AddINotifyPropertyChangedInterface]
    public class GameMapModel

    public ObservableCollection<GameMapNode> GameMapNodes get; set; = new ObservableCollection<GameMapNode>();
    public GameMapNode SelectedNode get; set;
    public BitmapImage Background get; set; = GameMap.jpg; //Link removed for forum post.


    public GameMapModel()

    //SelectedNode = new GameMapNode(0, 0, Brushes.White, "Default");



    [AddINotifyPropertyChangedInterface]
    public class GameMapNode

    public int X get; set; = 0;
    public int Y get; set; = 0;
    public Brush Colour get; set; = Brushes.Gray;
    public string Name get; set; = "Default";
    public bool Pulse get; set; = false;
    public bool Spin get; set; = false;
    public bool Throb get; set; = false;
    public bool Bounce get; set; = false;

    public GameMapNode(int x, int y, Brush colour, String name)

    X = x;
    Y = y;
    //Colour = colour;
    Name = name;


    public void ChangeTeam()

    if (Colour == Brushes.Blue)

    Colour = Brushes.Red;
    Spin = true;
    Bounce = true;
    Pulse = true;
    Throb = true;

    else

    Colour = Brushes.Blue;
    Spin = false;
    Bounce = false;
    Pulse = false;
    Throb = false;





    I am then have a UserControl that renders the map background and nodes based on the contents of the GameMapModel:



     <Grid Grid.Column="1" Name="MapGrid" MouseMove="Grid_MouseMove" MouseUp="Grid_MouseUp" Width="Binding GameMap.Background.Width" Height="Binding GameMap.Background.Height" Background="Black">
    <Image Source="Binding GameMap.Background" Stretch="Fill"/>

    <ItemsControl ItemsSource="Binding GameMap.GameMapNodes">

    <ItemsControl.ItemsPanel>
    <ItemsPanelTemplate>
    <Canvas Name="MapCanvas" Width="Binding Background.Width" Height="Binding Background.Height" MinHeight="240" MinWidth="320" IsItemsHost="True"/>
    </ItemsPanelTemplate>
    </ItemsControl.ItemsPanel>

    <ItemsControl.ItemContainerStyle>
    <Style TargetType="ContentPresenter">
    <Setter Property="Canvas.Left" Value="Binding X" />
    <Setter Property="Canvas.Top" Value="Binding Y" />
    <Setter Property="ContentTemplate">
    <Setter.Value>
    <DataTemplate>
    <Grid>
    <!-- <Rectangle x:Name="rect2" Stroke="Binding GameMap.Colour" StrokeThickness="20" Width="10" Height="10" /> -->

    <Rectangle x:Name="rect1" Stroke="Binding Colour" MouseRightButtonDown="Rectangle_MouseRightButtonDown" MouseLeftButtonDown="Rectangle_MouseLeftButtonDown" StrokeThickness="20" Width="10" Height="10">

    <Rectangle.RenderTransform>
    <TransformGroup>
    <RotateTransform x:Name="noFreeze" CenterX="5" CenterY="5"/>
    <TranslateTransform x:Name="noFreeze2" />
    <ScaleTransform x:Name="NoFreeze3" CenterX="5" CenterY="5"/>
    </TransformGroup>
    </Rectangle.RenderTransform>

    <Rectangle.Style >
    <Style TargetType="Rectangle" x:Name="RectangleStyle">
    <Style.Triggers>

    <DataTrigger Binding="Binding Pulse" Value="True" x:Name="PulseDataTrigger">
    <DataTrigger.EnterActions>
    <BeginStoryboard x:Name="PulseAnimation">
    <Storyboard>
    <DoubleAnimation Storyboard.TargetProperty="Opacity" To="0.5" Duration="0:0:1" RepeatBehavior="Forever" AutoReverse="True"/>
    </Storyboard>
    </BeginStoryboard>
    </DataTrigger.EnterActions>
    <DataTrigger.ExitActions>
    <StopStoryboard BeginStoryboardName="PulseAnimation"/>
    </DataTrigger.ExitActions>
    </DataTrigger>

    <DataTrigger Binding="Binding Spin" Value="True">
    <DataTrigger.EnterActions>
    <BeginStoryboard x:Name="SpinAnimation">
    <Storyboard>
    <DoubleAnimation Storyboard.TargetProperty="(Rectangle.RenderTransform).(TransformGroup.Children)[0].(RotateTransform.Angle)" To="-360" Duration="0:0:4" RepeatBehavior="Forever" />
    </Storyboard>
    </BeginStoryboard>
    </DataTrigger.EnterActions>
    <DataTrigger.ExitActions>
    <StopStoryboard BeginStoryboardName="SpinAnimation"/>
    </DataTrigger.ExitActions>
    </DataTrigger>

    <DataTrigger Binding="Binding Bounce" Value="True">
    <DataTrigger.EnterActions>
    <BeginStoryboard x:Name="BounceAnimation">
    <Storyboard>
    <DoubleAnimation Storyboard.TargetProperty="(Rectangle.RenderTransform).(TransformGroup.Children)[1].(TranslateTransform.Y)" From="5" To="-5" Duration="0:0:1" RepeatBehavior="Forever" AutoReverse="True"/>
    </Storyboard>
    </BeginStoryboard>
    </DataTrigger.EnterActions>
    <DataTrigger.ExitActions>
    <StopStoryboard BeginStoryboardName="BounceAnimation"/>
    </DataTrigger.ExitActions>
    </DataTrigger>

    <DataTrigger Binding="Binding Throb" Value="True">
    <DataTrigger.EnterActions>
    <BeginStoryboard x:Name="ThrobAnimation">
    <Storyboard>
    <DoubleAnimation Storyboard.TargetProperty="(Rectangle.RenderTransform).(TransformGroup.Children)[2].(ScaleTransform.ScaleX)" From="1" To="2" Duration="0:0:1" RepeatBehavior="Forever" AutoReverse="True"/>
    <DoubleAnimation Storyboard.TargetProperty="(Rectangle.RenderTransform).(TransformGroup.Children)[2].(ScaleTransform.ScaleY)" From="1" To="2" Duration="0:0:1" RepeatBehavior="Forever" AutoReverse="True"/>
    </Storyboard>
    </BeginStoryboard>
    </DataTrigger.EnterActions>
    <DataTrigger.ExitActions>
    <StopStoryboard BeginStoryboardName="ThrobAnimation"/>
    </DataTrigger.ExitActions>
    </DataTrigger>

    </Style.Triggers>
    </Style>
    </Rectangle.Style>
    </Rectangle>
    </Grid>
    </DataTemplate>
    </Setter.Value>
    </Setter>
    </Style>
    </ItemsControl.ItemContainerStyle>
    </ItemsControl>
    </Grid>


    Now all this works fine IF Spin, Bounce and Throb are false when I create a new instance of GameMapNode and add to the collection, after that, I can set any and all to true and animations work as expected.



    If I set any of those 3 to be true during object creation then I get the following error and the program crashes:




    System.Windows.Markup.XamlParseException: ''[Unknown]' property does not point to a DependencyObject in path '(0).(1)[0].(2)'.'




    If I comment out the Spin/Throb/Bounce DoubleAnimation blocks of the XAML, then the animations don't work, but the program doesn't crash.



    The same is NOT true for the Opacity animation which works fine, even if Pulse is set to true during object creation.



    This makes me think it's something to do with TransformGroup implementation as this is NOT used for the pulse. Maybe they're not loaded before the DataTrigger is first tried?



    This is my first real WPF application and I have a great mentor helping me through it, but even he's stumped. Any help of suggestions would be greatly appreciated :)










    share|improve this question























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      Preface



      I am writing a program that has a map class that contains a background image and list (ObservableCollection) of nodes that have colour, location and animation properties. A WPF application over the top has this referenced



      Problem



      I have an object of type GameMapModel that contains an observable collection of type GameMapNode:



       [AddINotifyPropertyChangedInterface]
      public class GameMapModel

      public ObservableCollection<GameMapNode> GameMapNodes get; set; = new ObservableCollection<GameMapNode>();
      public GameMapNode SelectedNode get; set;
      public BitmapImage Background get; set; = GameMap.jpg; //Link removed for forum post.


      public GameMapModel()

      //SelectedNode = new GameMapNode(0, 0, Brushes.White, "Default");



      [AddINotifyPropertyChangedInterface]
      public class GameMapNode

      public int X get; set; = 0;
      public int Y get; set; = 0;
      public Brush Colour get; set; = Brushes.Gray;
      public string Name get; set; = "Default";
      public bool Pulse get; set; = false;
      public bool Spin get; set; = false;
      public bool Throb get; set; = false;
      public bool Bounce get; set; = false;

      public GameMapNode(int x, int y, Brush colour, String name)

      X = x;
      Y = y;
      //Colour = colour;
      Name = name;


      public void ChangeTeam()

      if (Colour == Brushes.Blue)

      Colour = Brushes.Red;
      Spin = true;
      Bounce = true;
      Pulse = true;
      Throb = true;

      else

      Colour = Brushes.Blue;
      Spin = false;
      Bounce = false;
      Pulse = false;
      Throb = false;





      I am then have a UserControl that renders the map background and nodes based on the contents of the GameMapModel:



       <Grid Grid.Column="1" Name="MapGrid" MouseMove="Grid_MouseMove" MouseUp="Grid_MouseUp" Width="Binding GameMap.Background.Width" Height="Binding GameMap.Background.Height" Background="Black">
      <Image Source="Binding GameMap.Background" Stretch="Fill"/>

      <ItemsControl ItemsSource="Binding GameMap.GameMapNodes">

      <ItemsControl.ItemsPanel>
      <ItemsPanelTemplate>
      <Canvas Name="MapCanvas" Width="Binding Background.Width" Height="Binding Background.Height" MinHeight="240" MinWidth="320" IsItemsHost="True"/>
      </ItemsPanelTemplate>
      </ItemsControl.ItemsPanel>

      <ItemsControl.ItemContainerStyle>
      <Style TargetType="ContentPresenter">
      <Setter Property="Canvas.Left" Value="Binding X" />
      <Setter Property="Canvas.Top" Value="Binding Y" />
      <Setter Property="ContentTemplate">
      <Setter.Value>
      <DataTemplate>
      <Grid>
      <!-- <Rectangle x:Name="rect2" Stroke="Binding GameMap.Colour" StrokeThickness="20" Width="10" Height="10" /> -->

      <Rectangle x:Name="rect1" Stroke="Binding Colour" MouseRightButtonDown="Rectangle_MouseRightButtonDown" MouseLeftButtonDown="Rectangle_MouseLeftButtonDown" StrokeThickness="20" Width="10" Height="10">

      <Rectangle.RenderTransform>
      <TransformGroup>
      <RotateTransform x:Name="noFreeze" CenterX="5" CenterY="5"/>
      <TranslateTransform x:Name="noFreeze2" />
      <ScaleTransform x:Name="NoFreeze3" CenterX="5" CenterY="5"/>
      </TransformGroup>
      </Rectangle.RenderTransform>

      <Rectangle.Style >
      <Style TargetType="Rectangle" x:Name="RectangleStyle">
      <Style.Triggers>

      <DataTrigger Binding="Binding Pulse" Value="True" x:Name="PulseDataTrigger">
      <DataTrigger.EnterActions>
      <BeginStoryboard x:Name="PulseAnimation">
      <Storyboard>
      <DoubleAnimation Storyboard.TargetProperty="Opacity" To="0.5" Duration="0:0:1" RepeatBehavior="Forever" AutoReverse="True"/>
      </Storyboard>
      </BeginStoryboard>
      </DataTrigger.EnterActions>
      <DataTrigger.ExitActions>
      <StopStoryboard BeginStoryboardName="PulseAnimation"/>
      </DataTrigger.ExitActions>
      </DataTrigger>

      <DataTrigger Binding="Binding Spin" Value="True">
      <DataTrigger.EnterActions>
      <BeginStoryboard x:Name="SpinAnimation">
      <Storyboard>
      <DoubleAnimation Storyboard.TargetProperty="(Rectangle.RenderTransform).(TransformGroup.Children)[0].(RotateTransform.Angle)" To="-360" Duration="0:0:4" RepeatBehavior="Forever" />
      </Storyboard>
      </BeginStoryboard>
      </DataTrigger.EnterActions>
      <DataTrigger.ExitActions>
      <StopStoryboard BeginStoryboardName="SpinAnimation"/>
      </DataTrigger.ExitActions>
      </DataTrigger>

      <DataTrigger Binding="Binding Bounce" Value="True">
      <DataTrigger.EnterActions>
      <BeginStoryboard x:Name="BounceAnimation">
      <Storyboard>
      <DoubleAnimation Storyboard.TargetProperty="(Rectangle.RenderTransform).(TransformGroup.Children)[1].(TranslateTransform.Y)" From="5" To="-5" Duration="0:0:1" RepeatBehavior="Forever" AutoReverse="True"/>
      </Storyboard>
      </BeginStoryboard>
      </DataTrigger.EnterActions>
      <DataTrigger.ExitActions>
      <StopStoryboard BeginStoryboardName="BounceAnimation"/>
      </DataTrigger.ExitActions>
      </DataTrigger>

      <DataTrigger Binding="Binding Throb" Value="True">
      <DataTrigger.EnterActions>
      <BeginStoryboard x:Name="ThrobAnimation">
      <Storyboard>
      <DoubleAnimation Storyboard.TargetProperty="(Rectangle.RenderTransform).(TransformGroup.Children)[2].(ScaleTransform.ScaleX)" From="1" To="2" Duration="0:0:1" RepeatBehavior="Forever" AutoReverse="True"/>
      <DoubleAnimation Storyboard.TargetProperty="(Rectangle.RenderTransform).(TransformGroup.Children)[2].(ScaleTransform.ScaleY)" From="1" To="2" Duration="0:0:1" RepeatBehavior="Forever" AutoReverse="True"/>
      </Storyboard>
      </BeginStoryboard>
      </DataTrigger.EnterActions>
      <DataTrigger.ExitActions>
      <StopStoryboard BeginStoryboardName="ThrobAnimation"/>
      </DataTrigger.ExitActions>
      </DataTrigger>

      </Style.Triggers>
      </Style>
      </Rectangle.Style>
      </Rectangle>
      </Grid>
      </DataTemplate>
      </Setter.Value>
      </Setter>
      </Style>
      </ItemsControl.ItemContainerStyle>
      </ItemsControl>
      </Grid>


      Now all this works fine IF Spin, Bounce and Throb are false when I create a new instance of GameMapNode and add to the collection, after that, I can set any and all to true and animations work as expected.



      If I set any of those 3 to be true during object creation then I get the following error and the program crashes:




      System.Windows.Markup.XamlParseException: ''[Unknown]' property does not point to a DependencyObject in path '(0).(1)[0].(2)'.'




      If I comment out the Spin/Throb/Bounce DoubleAnimation blocks of the XAML, then the animations don't work, but the program doesn't crash.



      The same is NOT true for the Opacity animation which works fine, even if Pulse is set to true during object creation.



      This makes me think it's something to do with TransformGroup implementation as this is NOT used for the pulse. Maybe they're not loaded before the DataTrigger is first tried?



      This is my first real WPF application and I have a great mentor helping me through it, but even he's stumped. Any help of suggestions would be greatly appreciated :)










      share|improve this question













      Preface



      I am writing a program that has a map class that contains a background image and list (ObservableCollection) of nodes that have colour, location and animation properties. A WPF application over the top has this referenced



      Problem



      I have an object of type GameMapModel that contains an observable collection of type GameMapNode:



       [AddINotifyPropertyChangedInterface]
      public class GameMapModel

      public ObservableCollection<GameMapNode> GameMapNodes get; set; = new ObservableCollection<GameMapNode>();
      public GameMapNode SelectedNode get; set;
      public BitmapImage Background get; set; = GameMap.jpg; //Link removed for forum post.


      public GameMapModel()

      //SelectedNode = new GameMapNode(0, 0, Brushes.White, "Default");



      [AddINotifyPropertyChangedInterface]
      public class GameMapNode

      public int X get; set; = 0;
      public int Y get; set; = 0;
      public Brush Colour get; set; = Brushes.Gray;
      public string Name get; set; = "Default";
      public bool Pulse get; set; = false;
      public bool Spin get; set; = false;
      public bool Throb get; set; = false;
      public bool Bounce get; set; = false;

      public GameMapNode(int x, int y, Brush colour, String name)

      X = x;
      Y = y;
      //Colour = colour;
      Name = name;


      public void ChangeTeam()

      if (Colour == Brushes.Blue)

      Colour = Brushes.Red;
      Spin = true;
      Bounce = true;
      Pulse = true;
      Throb = true;

      else

      Colour = Brushes.Blue;
      Spin = false;
      Bounce = false;
      Pulse = false;
      Throb = false;





      I am then have a UserControl that renders the map background and nodes based on the contents of the GameMapModel:



       <Grid Grid.Column="1" Name="MapGrid" MouseMove="Grid_MouseMove" MouseUp="Grid_MouseUp" Width="Binding GameMap.Background.Width" Height="Binding GameMap.Background.Height" Background="Black">
      <Image Source="Binding GameMap.Background" Stretch="Fill"/>

      <ItemsControl ItemsSource="Binding GameMap.GameMapNodes">

      <ItemsControl.ItemsPanel>
      <ItemsPanelTemplate>
      <Canvas Name="MapCanvas" Width="Binding Background.Width" Height="Binding Background.Height" MinHeight="240" MinWidth="320" IsItemsHost="True"/>
      </ItemsPanelTemplate>
      </ItemsControl.ItemsPanel>

      <ItemsControl.ItemContainerStyle>
      <Style TargetType="ContentPresenter">
      <Setter Property="Canvas.Left" Value="Binding X" />
      <Setter Property="Canvas.Top" Value="Binding Y" />
      <Setter Property="ContentTemplate">
      <Setter.Value>
      <DataTemplate>
      <Grid>
      <!-- <Rectangle x:Name="rect2" Stroke="Binding GameMap.Colour" StrokeThickness="20" Width="10" Height="10" /> -->

      <Rectangle x:Name="rect1" Stroke="Binding Colour" MouseRightButtonDown="Rectangle_MouseRightButtonDown" MouseLeftButtonDown="Rectangle_MouseLeftButtonDown" StrokeThickness="20" Width="10" Height="10">

      <Rectangle.RenderTransform>
      <TransformGroup>
      <RotateTransform x:Name="noFreeze" CenterX="5" CenterY="5"/>
      <TranslateTransform x:Name="noFreeze2" />
      <ScaleTransform x:Name="NoFreeze3" CenterX="5" CenterY="5"/>
      </TransformGroup>
      </Rectangle.RenderTransform>

      <Rectangle.Style >
      <Style TargetType="Rectangle" x:Name="RectangleStyle">
      <Style.Triggers>

      <DataTrigger Binding="Binding Pulse" Value="True" x:Name="PulseDataTrigger">
      <DataTrigger.EnterActions>
      <BeginStoryboard x:Name="PulseAnimation">
      <Storyboard>
      <DoubleAnimation Storyboard.TargetProperty="Opacity" To="0.5" Duration="0:0:1" RepeatBehavior="Forever" AutoReverse="True"/>
      </Storyboard>
      </BeginStoryboard>
      </DataTrigger.EnterActions>
      <DataTrigger.ExitActions>
      <StopStoryboard BeginStoryboardName="PulseAnimation"/>
      </DataTrigger.ExitActions>
      </DataTrigger>

      <DataTrigger Binding="Binding Spin" Value="True">
      <DataTrigger.EnterActions>
      <BeginStoryboard x:Name="SpinAnimation">
      <Storyboard>
      <DoubleAnimation Storyboard.TargetProperty="(Rectangle.RenderTransform).(TransformGroup.Children)[0].(RotateTransform.Angle)" To="-360" Duration="0:0:4" RepeatBehavior="Forever" />
      </Storyboard>
      </BeginStoryboard>
      </DataTrigger.EnterActions>
      <DataTrigger.ExitActions>
      <StopStoryboard BeginStoryboardName="SpinAnimation"/>
      </DataTrigger.ExitActions>
      </DataTrigger>

      <DataTrigger Binding="Binding Bounce" Value="True">
      <DataTrigger.EnterActions>
      <BeginStoryboard x:Name="BounceAnimation">
      <Storyboard>
      <DoubleAnimation Storyboard.TargetProperty="(Rectangle.RenderTransform).(TransformGroup.Children)[1].(TranslateTransform.Y)" From="5" To="-5" Duration="0:0:1" RepeatBehavior="Forever" AutoReverse="True"/>
      </Storyboard>
      </BeginStoryboard>
      </DataTrigger.EnterActions>
      <DataTrigger.ExitActions>
      <StopStoryboard BeginStoryboardName="BounceAnimation"/>
      </DataTrigger.ExitActions>
      </DataTrigger>

      <DataTrigger Binding="Binding Throb" Value="True">
      <DataTrigger.EnterActions>
      <BeginStoryboard x:Name="ThrobAnimation">
      <Storyboard>
      <DoubleAnimation Storyboard.TargetProperty="(Rectangle.RenderTransform).(TransformGroup.Children)[2].(ScaleTransform.ScaleX)" From="1" To="2" Duration="0:0:1" RepeatBehavior="Forever" AutoReverse="True"/>
      <DoubleAnimation Storyboard.TargetProperty="(Rectangle.RenderTransform).(TransformGroup.Children)[2].(ScaleTransform.ScaleY)" From="1" To="2" Duration="0:0:1" RepeatBehavior="Forever" AutoReverse="True"/>
      </Storyboard>
      </BeginStoryboard>
      </DataTrigger.EnterActions>
      <DataTrigger.ExitActions>
      <StopStoryboard BeginStoryboardName="ThrobAnimation"/>
      </DataTrigger.ExitActions>
      </DataTrigger>

      </Style.Triggers>
      </Style>
      </Rectangle.Style>
      </Rectangle>
      </Grid>
      </DataTemplate>
      </Setter.Value>
      </Setter>
      </Style>
      </ItemsControl.ItemContainerStyle>
      </ItemsControl>
      </Grid>


      Now all this works fine IF Spin, Bounce and Throb are false when I create a new instance of GameMapNode and add to the collection, after that, I can set any and all to true and animations work as expected.



      If I set any of those 3 to be true during object creation then I get the following error and the program crashes:




      System.Windows.Markup.XamlParseException: ''[Unknown]' property does not point to a DependencyObject in path '(0).(1)[0].(2)'.'




      If I comment out the Spin/Throb/Bounce DoubleAnimation blocks of the XAML, then the animations don't work, but the program doesn't crash.



      The same is NOT true for the Opacity animation which works fine, even if Pulse is set to true during object creation.



      This makes me think it's something to do with TransformGroup implementation as this is NOT used for the pulse. Maybe they're not loaded before the DataTrigger is first tried?



      This is my first real WPF application and I have a great mentor helping me through it, but even he's stumped. Any help of suggestions would be greatly appreciated :)







      xaml animation observablecollection datatrigger rendertransform






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 10 at 16:52









      Pyro

      13




      13



























          active

          oldest

          votes











          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













           

          draft saved


          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53241209%2fcrash-when-animating-itemscontrol-through-datatriggers%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown






























          active

          oldest

          votes













          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes















           

          draft saved


          draft discarded















































           


          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53241209%2fcrash-when-animating-itemscontrol-through-datatriggers%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          這個網誌中的熱門文章

          How to read a connectionString WITH PROVIDER in .NET Core?

          In R, how to develop a multiplot heatmap.2 figure showing key labels successfully

          Museum of Modern and Contemporary Art of Trento and Rovereto