Silverlight TemplateBinding to RotateTransform
Posted
by Trog Dog
on Stack Overflow
See other posts from Stack Overflow
or by Trog Dog
Published on 2010-01-23T13:45:12Z
Indexed on
2010/05/11
3:44 UTC
Read the original article
Hit count: 508
I am trying to create the simplest Silverlight templated control, and I can't seem to get TemplateBinding to work on the Angle property of a RotateTransform.
Here's the ControlTemplate from generic.xaml:
<ControlTemplate TargetType="local:CtlKnob">
<Grid x:Name="grid" RenderTransformOrigin="0.5,0.5">
<Grid.RenderTransform>
<TransformGroup>
<RotateTransform Angle="{TemplateBinding Angle}"/> <!-- This does not work -->
<!-- <RotateTransform Angle="70"/> --> <!-- This works -->
</TransformGroup>
</Grid.RenderTransform>
<Ellipse Stroke="#FFB70404" StrokeThickness="19"/>
<Ellipse Stroke="White" StrokeThickness="2" Height="16" VerticalAlignment="Top"
HorizontalAlignment="Center" Width="16" Margin="0,2,0,0"/>
</Grid>
</ControlTemplate>
Here's the C#:
using System.Windows;
using System.Windows.Controls;
namespace CtlKnob
{
public class CtlKnob : Control
{
public CtlKnob()
{
this.DefaultStyleKey = typeof(CtlKnob);
}
public static readonly DependencyProperty AngleProperty =
DependencyProperty.Register("Angle", typeof(double), typeof(CtlKnob), null);
public double Angle
{
get { return (double)GetValue(AngleProperty); }
set { SetValue(AngleProperty,value); }
}
}
}
© Stack Overflow or respective owner