c# - How to write Decorator XAML custom control for Windows Runtime? -


wpf has decorator class can contain single child element.

windows runtime has no decorator class has similar border class can contain child element. unfortunately border class sealed.

i can derive control , write controltemplate contentpresenter child.

how border class written? here's example not working.

[contentproperty(name = "child")] public class textblockdecorator : frameworkelement {     public static readonly dependencyproperty contentproperty = dependencyproperty.register(         "child", typeof(textblock), typeof(textblockdecorator), new propertymetadata(null));      public textblock child     {         { return (textblock)getvalue(contentproperty); }         set { setvalue(contentproperty, value); }     } } 

when use child textblock not shown. how can add child decorator element? think, i'm missing call addvisualchild... or similar

windows::ui::xaml doesn't have decorator concept wpf does. adornment layer unique wpf , not implemented in other xaml frameworks such silverlight , windows::ui::xaml. can create control contains child control (or controls) , draws around them, can't same way windows::ui::xaml::controls::border does. border frameworkelement rather control , there isn't external access needed rendering.

for use i'd create custom control derived contentcontrol , edit template show desired decorations. using contentcontrol , contentpresenter can use same "decorator" content , not hard-code textblocks.

here's quick demo puts circle @ 4 corners:

xaml:

<style targettype="local:decorator" >     <setter property="template">         <setter.value>             <controltemplate targettype="local:decorator">                 <grid                     background="{templatebinding background}"                     minheight="30"                     >                     <contentpresenter horizontalalignment="center" verticalalignment="center" margin="5"/>                     <ellipse height="10" width="10" fill="{templatebinding background}" stroke="{templatebinding foreground}" horizontalalignment="left" verticalalignment="top"/>                     <ellipse height="10" width="10" fill="{templatebinding background}" stroke="{templatebinding foreground}" horizontalalignment="left" verticalalignment="bottom"/>                     <ellipse height="10" width="10" fill="{templatebinding background}" stroke="{templatebinding foreground}" horizontalalignment="right" verticalalignment="top"/>                     <ellipse height="10" width="10" fill="{templatebinding background}" stroke="{templatebinding foreground}" horizontalalignment="right" verticalalignment="bottom"/>                 </grid>             </controltemplate>         </setter.value>     </setter> </style> 

code (unchanged templated control template):

public sealed class decorator : contentcontrol {     public decorator()     {         this.defaultstylekey = typeof(decorator);     } } 

Comments

Popular posts from this blog

java - Oracle EBS .ClassNotFoundException: oracle.apps.fnd.formsClient.FormsLauncher.class ERROR -

c# - how to use buttonedit in devexpress gridcontrol -

nvd3.js - angularjs-nvd3-directives setting color in legend as well as in chart elements -