我需要将我的WPF应用程序(具有Ribbon
)转换为使用矢量图形处理按钮等上的图像,而不是位图。到目前为止,我的工作已经完成,除了RibbonApplicationMenu
项目(使用RibbonApplicationMenu.ImageSource
属性)和ImageSource
设置显示在功能区菜单项左侧的图形之外。如何将矢量图形(在XAML中定义)用作Ribbon菜单项的图像?
我的矢量图形的定义是这样的XAML
:但是
<ControlTemplate xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<ViewBox Width="148.854" Height="150.500">
<Canvas Width="148.854" Height="150.500">
<Path>
<!-- . . . yadda yadda yadda . . . -->
</Path>
</Canvas>
<Viewbox>
</ControlTemplate>
这些渲染正确,当我将它们设置为是Button
的.Template
等
我想不通, ,如何将它们用于RibbonApplicationMenu
控件中显示的图像。只需设置RibbonApplicationMenu
的.Template
属性不起作用(它填充整个控件似乎打破其功能)。
我试图使用VisualBrush
然后渲染到一个RenderTargetBitmap
作为使用.ImageSource
(我也有在代码中大多作品背后的原因,我不会进入):
ContentControl cc = new ContentControl(); // just picked ContentControl as a test
cc.Template = myTemplate; // assume myTemplate has the proper ControlTemplate
VisualBrush visBrush = new VisualBrush();
visBrush.Visual = cc;
// not really sure about the parameters to this next line
RenderTargetBitmap rend =
new RenderTargetBitmap(148.854, 150.5, 120, 96, PixelFormats.Pbgra32);
rend.Render(cc);
RibbonApplicationMenuItem menu = new RibbonApplicationMenuItem();
menu.ImageSource = render;
这编译,但只显示图像将去的空白。如果我使用从图像文件加载的BitmapImage
作为.ImageSource
,它会正确显示。
任何想法,我可以得到这个工作?要做到这一点可能需要
对不起,我应该在我的代码中包含更多的细节。我确实为画布设定了一个尺寸(并且我在我的问题中编辑了这些属性)。我会尽量测量和排列。 – Pysul 2012-03-30 14:08:51
使用'.Measure'和'.Arrange'将功能显示在功能区中。我不确定它是否正是我所需要的,但它工作。尽管如此,它并没有正确排列,但我可能会摆弄它。 – Pysul 2012-03-30 14:54:49