wpf - Binding preference: Name or Type? -
knowing mycontrol
has depprop. px1
, binding should prefeer, line1
or line2
?
<usercontrol x:class="myproject.mycontrol" xmlns:my="clr-namespace:myproject" x:name="parentcontrol"> <canvas> <line x:name="line1" x1="{binding relativesource={relativesource ancestortype={x:type my:mycontrol}}, path=px1}" /> <line x:name="line2" x1="{binding elementname=parentcontrol, path=px1}" /> </canvas> </usercontrol>
i mean, should ensure uniqueness of name "parentcontrol" per possible parents in second case?
i prefer latter syntax in cases, it's easier read intent, long choose clear name parentcontrol. down side fails if change name, whereas first continue work.
side note: px1 doesn't need dp, long usercontrol implements inotifypropertychanged , notifies when px1 changes.
Comments
Post a Comment