小智 56
menutItem.Icon = new System.Windows.Controls.Image
{
Source = new BitmapImage(new Uri("images/sample.png", UriKind.Relative))
};
Run Code Online (Sandbox Code Playgroud)
Arc*_*rus 21
<MenuItem>
<MenuItem.Icon>
<Image>
<Image.Source>
<BitmapImage UriSource="/your_assembly;component/your_path_here/Image.png" />
</Image.Source>
</Image>
</MenuItem.Icon>
</MenuItem>
Run Code Online (Sandbox Code Playgroud)
只需确保您的图像也包含在项目文件中并标记为资源,您就可以了:)
Ian*_*anR 15
Arcturus的答案很好,因为它意味着您在项目中拥有图像文件而不是独立文件夹.
所以,在代码变成......
menutItem.Icon = new Image
{
Source = new BitmapImage(new Uri("pack://application:,,,/your_assembly;component/yourpath/Image.png"))
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
52497 次 |
| 最近记录: |