Featured post
c# - multiple uses of attached property does not work -
my guess i'm not understanding attached properties correctly. i'm trying convert flowdocument on richtextbox html string property in view model. have 2 richtextboxes using richtextboxassistant
class (thanks this blog post):
<richtextbox x:name="rtb_description" local:richtextboxassistant.bounddocument="{binding myvm.description, validatesondataerrors=true}"/> <richtextbox x:name="rtb_descriptionhowto" local:richtextboxassistant.bounddocument="{binding myvm.descriptionhowto, validatesondataerrors=true}" />
in richtextboxassistant
class, have dependency property:
public static readonly dependencyproperty bounddocument = dependencyproperty.registerattached( "bounddocument", typeof(string), typeof(richtextboxassistant), new frameworkpropertymetadata( null, frameworkpropertymetadataoptions.bindstwowaybydefault, bounddocumentchanged ) );
the problem bounddocumentchanged
method gets hit when change value in first richtextbox, rtb_description
, not when change value in rtb_descriptionhowto
. when change text or rtb_descriptionhowto
, never reach bounddocumentchanged
. result of richtextboxassistant
being static class? how can fix can use richtextboxassistant
multiple richtextboxes?
coline had right idea: tried removing attached property first richtextbox, , changing value of second richtextbox still didn't put me in bounddocumentchanged
. turns out descriptionhowto
property in view model null, instead of html string. when initialized @"<html><body></body></html>"
, things started working.
- Get link
- X
- Other Apps
Comments
Post a Comment