BulletDecorator.Bullet不能病急乱投医,而BulletDecorator不是控制所以它不能被模板化。
不过你可以通过定义一个控件模板的ContentControl中像这样获得纯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(或字典合并到它)以及与此包起来:
<Style TargetType="{x:Type local:MyBullet}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate
...
</Setter.Value>
</Setter>
</Style>
如果你这样做,你可以使用:
<local:MyBullet>
<TextBox />
</local:MyBullet>
随时随地在你的应用。