我在问 16x16 pixel images in RibbonApplicationMenuItem gets stretched如何使功能区菜单项中的图像变小(并且不会延伸到32x32,就像在任何情况下都需要一样)。
我得到了一个很好的答案,基于替换这些控件的控件模板,然后我开始认为我可以使用已经存在的模板,并在generic.xaml中设置修改器中的属性。
如何查看功能区控件具有哪些组件结构?右键单击“模板”属性并将控件模板解压缩到现有的xaml文件即可轻松完成。
我可以调查这样一个菜单项的整个组件结构。在这里和哪里,有命名的组件,我找到了一个名为“Image”的组件。
所以我尝试在generic.xaml中执行此操作:
<Style TargetType="{x:Type ribbon:RibbonApplicationMenuItem}">
<Setter Property="Image.Height" Value="16" />
<Setter Property="Image.Width" Value="16" />
</Style>
<Style TargetType="{x:Type ribbon:RibbonApplicationSplitMenuItem}">
<Setter Property="Image.Height" Value="16" />
<Setter Property="Image.Width" Value="16" />
</Style>
但我得到的只是:
嗯,它有一些影响,但真正发生了什么? 我做错了什么?我可以调整像这样的控件的命名图像吗?
答案 0 :(得分:0)
我从未尝试使用generic.xaml中的主题,但您可以创建一个新文件并创建一个新的resourcedictionary。现在插入样式并设置x:Key属性,如下所示:x:Key {x:Type ribbon:RibbonApplicationMenuItem}。现在转到App.xaml,看起来应该是这样的
<Application x:Class="Coba.WPF.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
StartupUri="MainPage.xaml">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionarySource="yourresourcedictionarypath.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
</Application>
答案 1 :(得分:0)
<Setter Property="Image.Height" Value="16" />
设置Image的任何实例的高度,而不是名称为“Image”的控件的高度。
并使用
<Setter TargetName="Image" Property="Height" Value="16" />
不起作用,因为您无法在模板中使用TargetName,除非它在触发器中。