.net - WPF Binding problem -
i want create wpf user control exposing property called innercaption. code below
xaml code
<usercontrol x:class="mycontrol.usercontrol1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> <grid> <textblock name="_innercaption" > hello</textblock> </grid> </usercontrol>
cs code behind
namespace mycontrol { /// <summary> /// interaction logic usercontrol1.xaml /// </summary> public partial class usercontrol1 : usercontrol { public usercontrol1() { initializecomponent(); } public textblock innercaption { { return (textblock)this.getvalue(innercaptionproperty); } set { this.setvalue(innercaptionproperty, value); } } public static readonly dependencyproperty innercaptionproperty = dependencyproperty.register( "innercaption", typeof(textblock), typeof(usercontrol1),new propertymetadata(false)); } }
the question is: want users able customize innercaption @ design time such as: modifying color, font style ... don't know how sigh tried use kinds of binding. it's futile. know, binding supports binding property, right? show me way pls! :(
i think might after more in line of sub-classing textblock which´ll allow make use of existing properties on control.
public class mycaptioncontrol : textblock { .... }
this enables bind normally:
<mycaptioncontrol fontsize="{binding mymodelsize}" text="{binding mymodelcaption}" />
you´re definatly in right direction creating dependency property if want bind these properties you´ll need 1 property per bindable value. like
public static readonly dependencyproperty foregroundcolor = .... public static readonly dependencyproperty backgroundcolor = ....
these directly mapped inner textblock-control in usercontrol mentioned think better of subclassing textblock.
Comments
Post a Comment