Windows Vista Beta | WinVistaBeta.com - Message | Binding to properties of a user control

October 07, 2008  
Subject: Binding to properties of a user control
Group: microsoft.public.windows.developer.winfx.avalon
Date: 2/17/2008 4:55:20 AM
From: Dave [Email Address Protection]

Just getting up to speed with WPF...

I've got a simple user control:

<UserControl x:Class="WpfApplication2.MyUserControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Height="300" Width="300">
<Button>Hello, world</Button>
</UserControl>

And I want to apply a transform to this when it is instantiated and
bind the animation to the transform:

<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="WpfApplication2.Window1"
Title="Window1" xmlns:d="http://schemas.microsoft.com/expression/
blend/2006"
xmlns:my="clr-namespace:WpfApplication2">

<StackPanel>
<my:MyUserControl>
<my:MyUserControl.RenderTransform>
<TranslateTransform x:Name="MyTransform" X="10"/>
</my:MyUserControl.RenderTransform>

<my:MyUserControl.Triggers>
<EventTrigger RoutedEvent="Button.Click" >
<BeginStoryboard>
<Storyboard>
<DoubleAnimation
Storyboard.TargetName="MyTransform" Storyboard.TargetProperty="X"
IsCumulative="True" By="100"></DoubleAnimation>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</my:MyUserControl.Triggers>

</my:MyUserControl>
</StackPanel>
</Window>

Doesn't compile.

error MC3093: Cannot set Name attribute value 'MyTransform' on element
'TranslateTransform'. 'TranslateTransform' is under the scope of
element 'MyUserControl', which already had a name registered when it
was defined in another scope. Line 11 Position 37.

Any ideas?

Back