我在WPF应用程序中工作。对于全局菜单,我使用Ribbon。我需要从Resource.resx向RibbonButton(LargeImageSource)添加图像。
我将资源样式添加到xaml文件:
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Resources/Styles.xaml" />
</ResourceDictionary.MergedDictionaries>
然后我将我的ImageConverter添加到xaml文件中:
<conv:ImageConverter x:Key="Conv" />
我的C#类ImageConverter:
public class ImageConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
if (value is Bitmap)
{
var stream = new MemoryStream();
((Bitmap)value).Save(stream, ImageFormat.Png);
BitmapImage bitmap = new BitmapImage();
bitmap.BeginInit();
bitmap.StreamSource = stream;
bitmap.EndInit();
return bitmap; // use when you need normal image
var conv = new FormatConvertedBitmap();
conv.BeginInit();
conv.Source = bitmap;
conv.DestinationFormat = PixelFormats.Gray32Float;
conv.EndInit();
return conv; // use when you need grayed image
}
return value;
}
但我现在不想将Binding Image带到RibbunButton:
<RibbonButton KeyTip="N"
Label="{x:Static res:Resources.New}"
LargeImageSource="{Binding Source={StaticResource res:Resources},Path=newBtn, Converter={StaticResource Conv}}"/>
但这不起作用。我做错了什么?
答案 0 :(得分:0)
我更改了RibbonButton的XAML代码:
$location.update_path('/notes/1');
更改我的ImageConverter:
"{Binding Source={x:Static res:Resources.newBtn}, Converter={StaticResource ImageConverter}}"