Reputation: 1322
I have a Slider
control with minimum value higher than 0. The int
type property in the VM that the slider's bound to therefore has a initial value outside of slider value range. How can I get the slider to update the VM property with its miminum value at application startup? Currently it's only updating once the operator uses the slider.
<Slider Grid.Column="2" Grid.Row="1" Minimum="2" Maximum="100"
AutoToolTipPlacement="BottomRight" AutoToolTipPrecision="0"
Value="{Binding Path=Controller.MotorModel.SelectedMovementSpeed}" />
EDIT:
My initial assumption that the View should define the operator's limits was wrong. As FCin wrote, the View should only display values, while the logic should be in the ViewModel. Here's my updated XAML:
<Slider Grid.Column="2" Grid.Row="1" AutoToolTipPlacement="BottomRight" AutoToolTipPrecision="0"
Minimum="{Binding Path=Controller.MotorModel.MinimumMovementSpeed}"
Maximum="{Binding Path=Controller.MotorModel.MaximumMovementSpeed}"
Value="{Binding Path=Controller.MotorModel.SelectedMovementSpeed, Mode=TwoWay}" />
Upvotes: 0
Views: 71
Reputation: 3925
Set your Minimum
value inside your ViewModel, not in the View. Views in MVVM should not contain any logic. They only display properties to a user. ViewModels should validate user's input based on bounded properties and methods.
Upvotes: 1