Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
WPF菜单项和图像共享相同的资源_Wpf_Xaml - Fatal编程技术网

WPF菜单项和图像共享相同的资源

WPF菜单项和图像共享相同的资源,wpf,xaml,Wpf,Xaml,如何在菜单项和图像控件之间共享图像或位图图像资源 MenuItem具有Icon属性,该属性需要图像,而图像具有Source属性,该属性需要字符串。如果我的页面中有以下内容,我将如何将它们链接到同一资源。资源: <BitmapImage x:Key="imgAccept" UriSource="Resources/Images/accept.png" /> 这可以设置为图像的源属性: <Image Source={StaticResource imgAccept} />

如何在菜单项和图像控件之间共享图像或位图图像资源

MenuItem具有Icon属性,该属性需要图像,而图像具有Source属性,该属性需要字符串。如果我的页面中有以下内容,我将如何将它们链接到同一资源。资源:

<BitmapImage x:Key="imgAccept" UriSource="Resources/Images/accept.png" />

这可以设置为图像的源属性:

<Image Source={StaticResource imgAccept} />

但不能用于MenuItem图标属性:

<MenuItem Header="New Entity ..." Icon={StaticResource imgAccept} />

这表明: 试试:

<MenuItem Header="New Entity ...">
    <MenuItem.Icon>
        <Image Source={StaticResource imgAccept} />
    </MenuItem.Icon>
</MenuItem>