考え方は簡単です。RibbonComboBox から期間を秒単位で選択し、それをアプリ インスタンス プロパティに保存します。基になるデータはミリ秒単位ですが、コンボでは秒単位で表示されます。
私のアプリのプロパティは、時間をミリ秒で保存します。
private int _updatePeriod;
public int UpdatePeriod
{
get { return _updatePeriod; }
set
{
_updatePeriod = value;
InvokePropertyChanged(new PropertyChangedEventArgs("UpdatePeriod"));
}
}
XAML では、可能な選択肢のリストを次のようにミリ単位で定義します。
<x:Array x:Key="UpdateFrequenciesCollection" Type="{x:Type System:Int32}" >
<System:Int32 >100</System:Int32>
<System:Int32 >200</System:Int32>
<System:Int32 >500</System:Int32>
<System:Int32 >1000</System:Int32>
<System:Int32 >2000</System:Int32>
</x:Array >
次に、リボン ツールバーのコンボ ボックスを次のように設定します。
<ribbon:RibbonComboBox IsEditable="False" AllowDrop="False" Grid.Column="1" Grid.Row="1" IsDropDownOpen="False">
<ribbon:RibbonGallery x:Name="RibbonGalleryUpdatePeriod" SelectedValue="{Binding Path=UpdatePeriod, Mode=TwoWay, Source={x:Static Application.Current}}">
<ribbon:RibbonGalleryCategory x:Name="RibbonGalleryCategoryUpdatePeriod" ItemTemplate="{StaticResource UpdatePeriodTemplate}" ItemsSource="{Binding Source={StaticResource UpdateFrequenciesCollection}}">
</ribbon:RibbonGalleryCategory>
</ribbon:RibbonGallery>
</ribbon:RibbonComboBox>
これは、コンボ ボックス項目の単純なテンプレートです。
<DataTemplate x:Key="UpdatePeriodTemplate">
<StackPanel Orientation="Horizontal" >
<TextBlock Text="{Binding Converter={StaticResource DivideConverter}, ConverterParameter=1000, StringFormat={}{0:0.0 s}}"/>
</StackPanel>
</DataTemplate>
コンボボックス<->UpdatePeriodで正しい値を設定して取得するため、機能的には問題ありません。ただし、ドロップダウンには常に赤い境界線があり、検証エラーを示していると思います。これを引き起こす原因、または何らかの方法でエラーをデバッグする方法はありますか?? とても有難い!