I have a property in my ViewModel called RelativeHeight
, which is a double ranging from 0 to 1.
In my View, I have an horizontal line whose width is the same of its container (via Element Binding
), but I want it to have its vertical position relative to the size of the container.
For example, if RelativeHeight
is 0.3
, and the container's ActualHeight
is 200
, then Line.X1
and Line.X2
would be 60
each.
Following code is what I got, but don't know how to use (or even if I should use in the first place) some IValueConverter
because usually I can't get properties from the view whan calling the Convert
method...
<Line Stroke="Red" Opacity="0.5" StrokeThickness="5"
X1="0" X2="{Binding ActualWidth, ElementName=Graphs}"
Y1="{Binding RelativeHeight, Converter=MaybeSomeConversion}"
Y2="{Binding RelativeHeight, Converter=MaybeSomeConversion}" />
Got it with
IMultiValueConverter
, like this (variable names in portuguese):and in codebehind: