Contentcontrol
<Button>, <scrollviewer>, <label>, <checkbox>, <radiobutton>, <tooltip>
1: contentcontrol class has a type of object content attribute, which can be anything. Eg: The content of the button control can be any form of element :( text, text + image, image) and a contenttemplate attribute can receive controls of the ememplate type.
2: The content attribute of contentcontrol can be implicitly expressed.
View code
< Button Margin = "4" Horizontalalignment = "Left" Padding = "4" > < Stackpanel Orientation = "Horizontal" > < Image Source = "Copy.png" Width = "16" Height = "16" /> < Textblock Text = "Copy" Margin =" Verticalalignment = "Center" Fontsize = "16" /> </ Stackpanel > </ Button >
It can also be explicitly expressed
View code
<ButtonContent="{Staticresource P1}"Fontsize= "16"Margin= "4"Padding= "4"Horizontalalignment= "Left"/>
3: content attribute setting rules for contentcontrol
-
- If the content attribute is string, textblock will be render. The text attribute of textblock is this string
- If the content attribute is implicitly expressed ( content is directly inserted in ... ) is a uielement object , the uielement is render. If it is a row of uielement ( ). If there are multiple rows ( + ) add a panel ( , , )
- If the contenttemplate attribute is null,ContentProperty is customObjectThenRenderedTextblockWith itsText attributesSet toTostring MethodOfContent attribute value (ObjectType), OtherwiseDatatempateApplied
-
Note:All types of attributes may not be set only in XAML, but can also be set in background. CS, where to use them flexibly. HoweverContentcontrolOfContentAttribute, you must firstContentcontrolDefine an X: Name = "? ", Then the background can be
View code
Headered contentcontrol:<Groupbox>
1: inherited from contentcontrol. Besides the existing content and contenttemplate attributes, there are two more attributes (HeaderTypeObject,HeadertemplateTypeDatatemplate). All four attributes comply with the preceding Property setting rules.
?. Content = ?. Header =NewBook {name="Windows Internals", Author="Mark russinovich", Yearpublished=2009};}
Itemscontrol