wpf - My Custom Event does not produce anything -


i'm trying create custom routedevent in order trigger animation whenever text property of textblock changes. class inherits textblock class , shadow text property. i'm using button in order change text property in other value. code not produce errors doesn't anything. i'm sure problem textchanged event because when replace let's mouseenter event, works ok.

public class mycustomtextblock inherits textblock  public shared readonly textchangedevent routedevent = eventmanager.registerroutedevent("textchanged", _                routingstrategy.bubble, gettype(routedeventargs), gettype(mycustomtextblock))  public custom event textchanged routedeventhandler     addhandler(byval value routedeventhandler)         me.addhandler(textchangedevent, value)     end addhandler      removehandler(byval value routedeventhandler)         me.removehandler(textchangedevent, value)     end removehandler      raiseevent(byval sender object, byval e system.windows.routedeventargs)         me.raiseevent(e)     end raiseevent end event  public shared shadows textproperty dependencyproperty =     dependencyproperty.register("text", gettype(string), gettype(mycustomtextblock),                                  new frameworkpropertymetadata(string.empty,                                     new propertychangedcallback(addressof textpropertychanged)))  private shared sub textpropertychanged(byval sender object, byval e dependencypropertychangedeventargs)     directcast(sender, mycustomtextblock).raiseevent(new routedeventargs(mycustomtextblock.textchangedevent)) end sub end class 

xaml

<window x:class="mainwindow"     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"     xmlns:local="clr-namespace:wpfapplication1"        title="mainwindow" height="350" width="525">  <window.resources>     <style targettype="local:mycustomtextblock">         <style.triggers>             <eventtrigger routedevent="local:mycustomtextblock.textchanged">                 <eventtrigger.actions>                     <beginstoryboard>                         <storyboard>                             <doubleanimation storyboard.targetproperty="fontsize" to="30" duration="0:0:1" />                         </storyboard>                     </beginstoryboard>                 </eventtrigger.actions>             </eventtrigger>         </style.triggers>     </style>        </window.resources>  <grid>     <local:mycustomtextblock x:name="textblock1" text="xxxxxxxxx" background="yellow" width="100" height="25" />     <button content="change text" height="23" horizontalalignment="left" margin="217,218,0,0" name="button1" verticalalignment="top" width="75" /> </grid> 

class main window        private sub button1_click(byval sender system.object, byval e       system.windows.routedeventargs) handles button1.click      textblock1.text = "apollon" end sub end class 

it looks problem you're creating new members conflict on base textbox. should consider using textchanged event exists on textbox, or if need own, name different. here far aren't doing base properties don't already.

the main issue specific question though appears new textproperty created. shouldn't hide dependency property on base class, because can't control 1 used in every situation, because there mechanisms built in make unnecessary. in case you've aggravated problem not implementing boilerplate code dp. because have no wrapper property, setting of text property code setting textbox.text, internally calling setvalue textbox.textproperty, hence skipping code entirely.

instead of declaring own textproperty can tack on metadata existing one. add change handler existing property add call static constructor:

        textproperty.overridemetadata(gettype(mycustomtextblock),                              new frameworkpropertymetadata(string.empty,                              new propertychangedcallback(addressof textpropertychanged))) 

Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -