c# - Bind Rect Width and Height in xaml -
i trying bind width , height of rect
in viewport
this:
<visualbrush.viewport> <rect width="{binding path=mywidth}" height="{binding path=myheight}"/> </visualbrush.viewport>
my binding works fine elsewhere here following error message:
a 'binding' cannot set on 'width' property of type 'rect'. 'binding' can set on dependencyproperty of dependencyobject.
edit understand error message. question how work around it. how bind height , width of rect?
use multibinding this:
<visualbrush.viewport> <multibinding> <multibinding.converter> <local:rectconverter/> </multibinding.converter> <binding path="mywidth"/> <binding path="myheight"/> </multibinding> </visualbrush.viewport>
with multi-value converter this:
public class rectconverter : imultivalueconverter { public object convert(object[] values, type targettype, object parameter, cultureinfo culture) { return new rect(0d, 0d, (double)values[0], (double)values[1]); } public object[] convertback(object value, type[] targettypes, object parameter, cultureinfo culture) { throw new notsupportedexception(); } }
Comments
Post a Comment