开发者

WPF MenuItem and Image share same resource

开发者 https://www.devze.com 2023-03-01 05:52 出处:网络
How would I share an Image or BitmapImage resource between an MenuItem and an Image control. 开发者_高级运维The MenuItem has the Icon property which expects an Image while the Image has an Source pro

How would I share an Image or BitmapImage resource between an MenuItem and an Image control.

开发者_高级运维The MenuItem has the Icon property which expects an Image while the Image has an Source property which expects an String. How would i link them to the same resource if I have the following in my Page.Resources:

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

This can be set as the Source property for the Image:

<Image Source={StaticResource imgAccept} />

But can't be used for the MenuItem Icon property:

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

That shows: http://i.stack.imgur.com/m4o62.png


Try:

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

精彩评论

暂无评论...
验证码 换一张
取 消