1, ordinary control overrides need to add a row
<horizontalalignment= "center" verticalalignment= "Center " Margin= "{TemplateBinding Padding}"></ ContentPresenter>
2, textbox, such as edit control rewrite, need to fill a line
<x:name= "PART_ContentHost"></ScrollViewer>
This is the only way to get into edit mode
Give me a chestnut:
<ControlTemplatex:key= "Roundtextboxtemplate"TargetType= "TextBox"> <BorderCornerradius= "5"BorderBrush= "Lightskyblue"borderthickness= "2"Background="{TemplateBinding Background}"Margin= "3"> <ScrollViewerx:name= "PART_ContentHost"></ScrollViewer> </Border> </ControlTemplate> <Stylex:key= "Roundtextboxstyle"TargetType= "TextBox"> <Setter Property= "Template"Value="{DynamicResource Resourcekey=roundtextboxtemplate}" ></Setter> </Style>
This is the simplest way to implement a TextBox rewrite style.
"WPF" TextBox style rewriting considerations