Hi I was wondering if there is possibility to get access to project properties resources form xaml. I need to create a menuItem icon, so normally I would do this that way
itemCopy = new MenuItem
{
Icon = System.Drawing.Icon.FromHandle(NameSpace.Properties.Resources.iconName.Get开发者_C百科Hicon())
};
However I would like to create the same icon directly from XAML without using code behind. Is this possible
You need to set up the respective namespace and do a static reference, e.g.
<Window ...
xmlns:prop="clr-namespace:Test.Properties"
Title="{Binding Source={x:Static prop:Resources.WinTitle}}">
If your reference does not provide an object of the right type or a method call is necessary you could use a ValueConverter.
Icons in resx resources are of type System.Drawing.Icon
, but WPF needs an ImageSource
. Just change the build action of the icon to "Resource" (not "Embedded Resource"), and refer to it directly in XAML:
<MenuItem Icon="Resources/yourIcon.ico"...
精彩评论