TemplateBinding doesn't work for my UserControl
Hi,
Binding + RelativeSource works, but TemplateBinding does not. What could be the reason?
Binding + RelativeSource works, but TemplateBinding does not. What could be the reason?
Code: Select all
class ENGINE_API RadialAngleControl final : public Noesis::UserControl
{
public:
RadialAngleControl() = default;
float GetAngle() const;
void SetAngle(float value);
inline static const Noesis::DependencyProperty* AngleProperty;
NS_DECLARE_REFLECTION(RadialAngleControl, UserControl)
};
}Code: Select all
NS_IMPLEMENT_REFLECTION(RadialAngleControl)
{
auto data = NsMeta<Noesis::UIElementData>(Noesis::TypeOf<SelfClass>());
data->RegisterProperty<float>(AngleProperty, "Angle", FrameworkPropertyMetadata::Create(45.f));
}Code: Select all
<ControlTemplate x:Key="Template.RadialAngleControl" TargetType="{x:Type RadialAngleControl}">
<Viewbox>
<Canvas Width="100" Height="100">
<Ellipse Width="100" Height="100" />
<-- Binding OK -->
<Line X1="50" X2="50" Y1="50" Y2="10">
<Line.RenderTransform>
<RotateTransform Angle="{Binding Path=Angle, RelativeSource={RelativeSource AncestorType={x:Type RadialAngleControl}}}" CenterX="50" CenterY="50" />
</Line.RenderTransform>
</Line>
<-- Binding not working -->
<Line X1="50" X2="50" Y1="50" Y2="10">
<Line.RenderTransform>
<RotateTransform Angle="{TemplateBinding Angle}" CenterX="50" CenterY="50" />
</Line.RenderTransform>
</Line>
</Canvas>
</Viewbox>
</ControlTemplate>-
-
sfernandez
Site Admin
- Posts: 3363
- Joined:
Re: TemplateBinding doesn't work for my UserControl
This happens because the RotateTransform doesn't have a TemplatedParent, so TemplateBinding can't find your control's property. In this case you have to use a RelativeSource with AncestorType as you indicated. I have verified this is the same behavior in WPF.
Who is online
Users browsing this forum: No registered users and 7 guests