开发者

WPF MenuItem and Image share same resource

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜