Hi guys,
I am try my best to make myself clear. I have two pages with one of them being Config page. In the config page, I have a RadCombox to choose a time span value. The code snippets are below.
As you can see from the above code, I binds the selected value to TimeRemaing property and I would use a customized converter named DetectionDurationConverter to turn 10 s, 10 minutes and 1 hour into a time span value in C#. Here is my converter.
For example, when I select a '10 s', it goes to ConvertBack method as expected and TimeRemaining is a 10 second time span value. Then I switched to another page and switched back, it goes to Convert method with TimeRemaining being 10 seonds still. Note, the method Convert would be entered twice. However, in the UI, no items have been selected. I just hope the selected item would be consistent with the value of TimeRemaining.
Thanks,
-J
I am try my best to make myself clear. I have two pages with one of them being Config page. In the config page, I have a RadCombox to choose a time span value. The code snippets are below.
<telerik:RadComboBox Width="125" FontSize="{DynamicResource FontSizeBig}" VerticalAlignment="Center" Height="32" Margin="0,0,5,0" SelectedValue="{Binding Realtime.TimeRemaining, Converter={StaticResource DetectionDurationConverter}, Source={StaticResource Locator}}"> <telerik:RadComboBoxItem Content="10 s" /> <telerik:RadComboBoxItem Content="10 minutes"/> <telerik:RadComboBoxItem Content="1 hour"/> <telerik:RadComboBoxItem Content="Custom" Margin="0"/></telerik:RadComboBox>As you can see from the above code, I binds the selected value to TimeRemaing property and I would use a customized converter named DetectionDurationConverter to turn 10 s, 10 minutes and 1 hour into a time span value in C#. Here is my converter.
public class DetectionDurationConverter : IValueConverter{ private static readonly string[] durationSet = new[] {"10 s", "10 minutes", "1 hour"}; public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { var timeSpan = (TimeSpan) value; if (timeSpan == TimeSpan.FromSeconds(10.0)) { return durationSet[0]; } else if (timeSpan == TimeSpan.FromMinutes(10.0)) { return durationSet[1]; } else if (timeSpan == TimeSpan.FromHours(1.0)) { return durationSet[2]; } return string.Empty; } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { var timeSpan = TimeSpan.MinValue; if (value is RadComboBoxItem) { var val = System.Convert.ToString((value as RadComboBoxItem).Content); if (val == durationSet[0]) { timeSpan = TimeSpan.FromSeconds(10.0); } else if (val == durationSet[1]) { timeSpan = TimeSpan.FromMinutes(10.0); } else if (val == durationSet[2]) { timeSpan = TimeSpan.FromHours(1.0); } } return timeSpan; }}For example, when I select a '10 s', it goes to ConvertBack method as expected and TimeRemaining is a 10 second time span value. Then I switched to another page and switched back, it goes to Convert method with TimeRemaining being 10 seonds still. Note, the method Convert would be entered twice. However, in the UI, no items have been selected. I just hope the selected item would be consistent with the value of TimeRemaining.
Thanks,
-J