I have problems getting the Targetname property in ANY setter to work (inside a datatemplate). How Do i access specific elements within a datatemplate to change/animate with a animation/property trigger
try putting Storyboard.TargetName="..." Storyboard.TargetProperty="..." on the DoubleAnimation instead of on the Storyboard. The reason for this is because those are "attached" properties that you set on children of the Storyboard, as opposed to on the Storyboard itself.
I too have been feeling stupid for asking such a question. My problems have been with animating a 3D rotation, but it all boils down to a similar path issue.
I'm going to look into eburkes suggestions, and hopefully the posts will resume after the new year.
It would seem to me to be a pretty major bug. It singlehandedly removes a significant ammount of functionality. The power that targetting names within datatemplates would afford would be impressive. I'd hope it would be a must-fix.
I'd just like to emphasize that this is within datatemplates. In freestanding code their fine. Is there some form of Identifiew to say that the target (tagged with x:Name) is within the template's scope
one other thing that's worked for me in the past is to move the Storyboard out into the resources section of the XAML and then reference the Storyboard from the BeginStoryboard object.
The only examples of targetname being used, or triggers being used for that matter, that i can find, are for standalone (non list-type) controls. Can anyone share some insight on using triggers/ targetnames in a datatemplate Is it SUPPOSED to work the same way and as such make me retarded, or is there something key that I'm missing.
As an example, when used as the itemtemplate for the listbox, the following template says that "MyTransform" cannot be found in the namespace System.Windows.DataTemplate.
I feel foolish bumping it this many times. I figure one of two things is happening. 1) This is such a stupid question everyone is SURE i should be able to figure it out on my own. 2) Nobody else is trying to do what I'm doing, which i find hard to believe.
The reason i put the targetproperty where it was is ialready tried it on the doubleanimation and it didnt work. I was desparate :) Thanks for the feedback though. I'll give that a shot, but ive tried something very similar before.
TargetName Does not work for me.
Bob McD
3) everyone is out of town over the holidays
try putting Storyboard.TargetName="..." Storyboard.TargetProperty="..." on the DoubleAnimation instead of on the Storyboard. The reason for this is because those are "attached" properties that you set on children of the Storyboard, as opposed to on the Storyboard itself.
StefanS
I too have been feeling stupid for asking such a question. My problems have been with animating a 3D rotation, but it all boils down to a similar path issue.
I'm going to look into eburkes suggestions, and hopefully the posts will resume after the new year.
Jon D.
Juval Lowy
Ruepen
It would seem to me to be a pretty major bug. It singlehandedly removes a significant ammount of functionality. The power that targetting names within datatemplates would afford would be impressive. I'd hope it would be a must-fix.
da_cobra
Lightning Lord
ConradC
one other thing that's worked for me in the past is to move the Storyboard out into the resources section of the XAML and then reference the Storyboard from the BeginStoryboard object.
e.g.,
<Resources>
<Storyboard x:Key="mysb">...</Storyboard>
</Resources>
...
<ControlTemplate.Triggers>
<EventTrigger RoutedEvent="ButtonBase.Click">
<EventTrigger.Actions>
<BeginStoryboard Storyboard={StaticResource mysb}.../>
...
Graham Harrison
one other thing: instead of trying to access the transform by name, try naming the rectangle and then change the TargetProperty to:
Storyboard.TargetProperty="(UIElement.RenderTransform).(TranslateTransform.X)"
ConradsW
As an example, when used as the itemtemplate for the listbox, the following template says that "MyTransform" cannot be found in the namespace System.Windows.DataTemplate.
<DataTemplate x:Key="StockTemplate">
<DataTemplate.Triggers>
<EventTrigger RoutedEvent="Control.MouseEnter">
<EventTrigger.Actions>
<BeginStoryboard>
<Storyboard Storyboard.TargetName="MyTransform" Storyboard.TargetProperty="X">
<DoubleAnimation From="0" To="200" DecelerationRatio=".15" AccelerationRatio=".20" AutoReverse="True"></DoubleAnimation>
</Storyboard>
</BeginStoryboard>
</EventTrigger.Actions>
</EventTrigger>
</DataTemplate.Triggers>
<Canvas Height="20" Width="310" >
<WrapPanel Width="300" Canvas.Left="20" Background="Green">
<WrapPanel.OpacityMask>
<LinearGradientBrush Opacity="1" StartPoint="0,1" EndPoint="0,0" >
<LinearGradientBrush.GradientStops>
<GradientStop Offset="0" Color="#00000000"></GradientStop>
<GradientStop Offset=".1" Color="White"></GradientStop>
</LinearGradientBrush.GradientStops>
</LinearGradientBrush>
</WrapPanel.OpacityMask>
<Button Height="20" Content="Logo"></Button>
<TextBlock Text="{Binding Name}"></TextBlock>
<TextBlock Text="{Binding Price}"></TextBlock>
<TextBlock>Up</TextBlock>
</WrapPanel>
<Rectangle Fill="GreenYellow" Opacity=".85" Width="10" Canvas.Top="2" Canvas.Left="5" Height="16">
<Rectangle.RenderTransform>
<TranslateTransform x:Name="MyTransform" X="0"></TranslateTransform>
</Rectangle.RenderTransform>
</Rectangle>
</Canvas>
</DataTemplate>
Reto Scherrer
Paul B
I figure one of two things is happening.
1) This is such a stupid question everyone is SURE i should be able to figure it out on my own.
2) Nobody else is trying to do what I'm doing, which i find hard to believe.
Any feedback on which one it is
Operator10
definitely let me know what you find because i've run into problems along the same lines.
also, don't forget that it *could* be a bug in the runtime, but this doesn't seem like much of an edge case that would have been missed in testing.
Steve Nunez
Thanks for the feedback though. I'll give that a shot, but ive tried something very similar before.