I need to show a box view underneath a list view to show an area for the list view stuff. For this I'm using AbsoluteLayout. Before I moved to "real" MVVM I had the code to calculate the box coordinates in code behind file.
double fractionalWidth = (_max - _min) / __maxValue; double xCoordinate = _min / _maxValue / (1.0 - fractionalWidth); AbsoluteLayout.SetLayoutBounds(boxView, new Rectangle(xCoordinate, 0, fractionalWidth, 1.0));
And then I have also a text for it which should be centered to the box view:
xCoordinate = boxView.X + (boxView.Width / 2) - (label.Width / 2); AbsoluteLayout.SetLayoutBounds(label, new Rectangle(xCoordinate, 0, AbsoluteLayout.AutoSize, AbsoluteLayout.AutoSize));
For the label positioning I also need the coordinates. The respective XAML implementation:
<AbsoluteLayout Grid.Column="1"> <BoxView x:Name="boxView" AbsoluteLayout.LayoutFlags="All" Color="#D8D8D8"/> <Label x:Name="label" AbsoluteLayout.LayoutBounds="0, 0, AutoSize, AutoSize" Text="Preferred Range" FontSize="12" TextColor="#9B9B9B" Margin="0,10,0,0" HorizontalOptions="Center" HorizontalTextAlignment="Center" VerticalTextAlignment="Center"/> </AbsoluteLayout>
So the question is, how should I implement this with MVVM? The _min, _max, and _maxValue are all dynamical. And because I need to calculate the coordinate I can't also use only XAML. If I bind the box view LayoutBound to rectangle in model view then the model view and view are really tightly coupled and if I have understood it correctly this shouldn't be the case in MVVM pattern.I also do not have the coordinates to calculate the right position for the label either in model view. In my opinion these things should be placed alway to behind code because model view should not care about positioning the stuff. How do I bind the needed values in code behind file to model view (if that is the "right" way to do things). I'm using MVVMLight if it makes a difference.