TemplateBinding doesn't work for my UserControl
Posted: 26 Feb 2025, 11:47
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>