WPF自定义控件中模板部件的样式
答
您的示例代码试图设置CustomControl
本身的Template
财产不的TextBox
的包含了CustomControl
内。当您未显示TextBox
的XAML时,如果您想要更改ControlTemplate
,则很难回答这样的问题。正因为如此,我只能“引导”你这是如何上的任何TextBox
来完成:
<Style TargetType="MyCustomControl">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type CustomControl}">
<Grid>
...
<TextBox Background="{Binding SomeBrushProperty}">
<TextBox.Template>
<ControlTemplate TargetType="{x:Type TextBox}">
<!--Define your TextBox ControlTemplate here-->
</ControlTemplate>
</TextBox.Template>
</TextBox>
...
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
在未来,请提供相关代码的所有,以帮助您快速获得答案,准确。
UPDATE >>>
好了,你的问题编辑后,我想我现在明白你的问题。但是,如果不更改CustomControl
的代码或为其提供新的ControlTemplate
(如我的第一个示例),则无法执行此操作。
如果可以更改代码,你首先需要创建NewTextValue
DependencyProperty
如要使用正确的类型,例如。一个Brush
。然后,你就必须改变CustomControl
的XAML定义,包括这个:
<TextBox Background="{Binding NewTextValue}">
+0
问题修改 – James
你的问题是在all..add有效的代码和说明,你想达到什么不清楚 – Nitin
问题修改 – James