【发布时间】:2023-10-05 16:53:01
【问题描述】:
我有一个RibbonComboBox 用于设置字体大小。它有一个RibbonGallery,列出了各种字体大小,显示在适当的FontSize:
<r:RibbonComboBox DataContext="{x:Static vm:RibbonDataModel.FontSizeComboBoxData}"
SelectionBoxWidth="30">
<r:RibbonGallery MaxColumnCount="1"
Command="{Binding Command}"
CommandParameter="{Binding SelectedItem}">
<r:RibbonGallery.GalleryItemTemplate>
<DataTemplate>
<Grid>
<TextBlock Text="{Binding}"
FontSize="{Binding}" />
</Grid>
</DataTemplate>
</r:RibbonGallery.GalleryItemTemplate>
</r:RibbonGallery>
</r:RibbonComboBox>
编辑这是我的 ViewModel:
public static RibbonDataModel
{
public static GalleryData<object> FontSizeComboBoxData
{
get
{
lock (LockObject)
{
const string key = "Font Size";
if (!DataCollection.ContainsKey(key))
{
var value = new GalleryData<object>
{
Command = HtmlDocumentCommands.ChangeFontSize,
Label = "Change Font Size",
ToolTipDescription = "Set the font to a specific size.",
ToolTipTitle = "Change Font Size",
};
var fontSizes = new GalleryCategoryData<object>();
var i = 9.0;
while (i <= 30)
{
fontSizes.GalleryItemDataCollection.Add(i);
i += 0.75;
}
value.CategoryDataCollection.Add(fontSizes);
DataCollection[key] = value;
}
return DataCollection[key] as GalleryData<object>;
}
}
}
}
一切都按预期工作,但在我从图库中选择一个项目后,它会显示在 RibbonComboBox 中,并带有与图库中相同的巨大(或微小)FontSize。
当所选项目的FontSize 显示在RibbonComboBox 中时,如何将其“重置”为默认值?
【问题讨论】:
-
你能发布你的 ViewModel 的代码吗?
-
按要求发布。
标签: wpf ribbon ribbon-control ribboncontrolslibrary windows-ribbon-framework