1
원을 표시하는 간단한 사용자 지정 컨트롤을 만들려고합니다. 이 컨트롤에는 Radius 속성이 있지만 불행히도 컨트롤에는 적용되지 않습니다. 다음은 템플릿은 다음과 같습니다WinRT의 사용자 지정 컨트롤과 TemplateBinding
<Style TargetType="local:SizedCircle">
<Setter Property="VerticalAlignment" Value="Center"/>
<Setter Property="HorizontalAlignment" Value="Center" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="local:SizedCircle">
<Border
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}">
<Ellipse Width="{TemplateBinding Radius}" Height="{TemplateBinding Radius}">
<Ellipse.Fill>
<SolidColorBrush Color="Red"/>
</Ellipse.Fill>
</Ellipse>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
그리고
namespace CustomControls
{
public sealed class SizedCircle : Control
{
public SizedCircle()
{
this.DefaultStyleKey = typeof(SizedCircle);
}
public string Radius
{
get { return (string)GetValue(RadiusProperty); }
set { SetValue(RadiusProperty, value); }
}
// Using a DependencyProperty as the backing store for Radius. This enables animation, styling, binding, etc...
public static readonly DependencyProperty RadiusProperty =
DependencyProperty.Register("Radius", typeof(string), typeof(SizedCircle), new PropertyMetadata(null));
}
}
은 그 때 나는이 컨트롤을 사용하려고 :
<local:SizedCircle Radius="50" />
을하지만 화면에 아무것도 볼 수 없습니다. 이 반경 속성은 적용되지 않습니다. 나는 무엇이 틀리게 douing하고 있냐?