BulletDecorator.Bullet이 스타일을 지정할 수 없으며, BulletDecorator가 제어되지
<local:MyDecorator>
<TextBlock />
</local:MyDecorator>
그래서 그것은 템플릿 화 될 수 없습니다.
이 같은 ContentControl을위한의 ControlTemplate을 정의하여 순수 XAML의 효과를 얻을 수있다 그러나 :
지금
<ControlTemplate x:Key="BulletTemplate" TargetType="{x:Type ContentControl}">
<BulletDecorator>
<BulletDecorator.Bullet>
...my bullet UIElement here...
</BulletDecorator.Bullet>
<ContentPresenter />
</BulletDecorator>
</ControlTemplate>
이처럼 사용할 수 있습니다
<ContentControl Template="{StaticResource BulletTemplate}">
<TextBlock />
</ContentControl>
당신은 단지 그것을 사용하는 경우 몇 번, "< ContentControl Template = ..."기술은 정상적으로 작동합니다. 당신이 더 자주 사용하려는 경우, 당신은 MyBullet 클래스를 정의 할 수 있습니다 :
public class MyBullet : ContentControl
{
static MyBullet()
{
DefaultStyleKey.OverrideMetadata(typeof(MyBullet), new FrameworkPropertyMetadata(typeof(MyBullet));
}
}
다음 테마/generic.xaml을로의 ControlTemplate 이동을 (또는 사전이 그것으로 합병)이 함께 포장 :
이렇게하면
<Style TargetType="{x:Type local:MyBullet}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate
...
</Setter.Value>
</Setter>
</Style>
, 당신은 사용할 수 있습니다 어디서나
<local:MyBullet>
<TextBox />
</local:MyBullet>
을 응용 프로그램에서.