I have windows where I have some controls(time period picker):
UPDATED
<ComboBox DisplayMemberPath="{Binding Path=Name}" ItemsSource="{Binding Periods}" Name="timeType" />
<Slider Value="20" Minimum="{Binding SelectedItem.Min, ElementName=timeType}" Maximum="{Binding SelectedItem.Max, ElementName=timeType}" Name="timeSlider" />
<Label Content="{Binding ElementName=timeSlider, Path=Value}" Name="timeValue" />
<Label Content="{Binding ElementName=timeSlider, Path=Minimum}" Name="timeValueMin" />
<Label Content="{Binding ElementName=timeSlider, Path=Maximum}" Name="timeValueMax" />
In window class I did property:
public class TimePeriodType {
public string Name { set; get; }
public int Min { set; get; }
public int Max { set; get; }
}
public List<TimePeriodType> Periods = new List<TimePeriodType>() {
new TimePeriodType() { Name="Hours", Max=6, Min=1 },
new TimePeriodType(){ Name="Minutes", Max=59, Min=20 }
};
And now I want to do somethink to update Slider values when I change value in Groupbox. Is there any possibility to do it?
Already I do it like this:
private void timeType_SelectionChanged( object sender, SelectionChangedEventArgs e ) {
var period = Periods.Single(p => p.Name == timeType.SelectedValue.ToString());
timeSlider.Minimum = period.Min;
timeSlider.Maximum = period.Max;
}
But for me it is not great solution.
Maybe you know simplier way to do it?
Ok I found solution.
There should be property with get method:
And in addition there should be following binding: