我正在我的WPF应用程序中创建自定义错误对话框,我想使用标准的Windows错误图标.我可以从WPF获取特定于操作系统的图标吗?如果没有,有没有人知道从哪里得到.pngs的透明度?或者知道在Windows中从哪里提取它们?
到目前为止,我的搜索结果都没有.
boh*_*nko 34
有一个SystemIcons类,但需要调整WPF需求(即转换Icon为ImageSource).
Len*_*rri 29
关于使用标准Microsoft图标.
绝大多数开发人员都不知道Visual Studio附带了一个图像库.所以这里有两个突出显示它的链接:
关于使用Microsoft Visual Studio 2010图像库.
关于使用Microsoft Visual Studio 2008图像库.
run*_*sun 10
这就是我在XAML中使用系统图标的方式:
xmlns:draw="clr-namespace:System.Drawing;assembly=System.Drawing"
...
<Image Source="{Binding Source={x:Static draw:SystemIcons.Warning},
Converter={StaticResource IconToImageSourceConverter},
Mode=OneWay}" />
Run Code Online (Sandbox Code Playgroud)
我使用这个转换器将Icon转换为ImageSource:
public class IconToImageSourceConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
var icon = value as Icon;
if (icon == null)
{
Trace.TraceWarning("Attempted to convert {0} instead of Icon object in IconToImageSourceConverter", value);
return null;
}
ImageSource imageSource = Imaging.CreateBitmapSourceFromHIcon(
icon.Handle,
Int32Rect.Empty,
BitmapSizeOptions.FromEmptyOptions());
return imageSource;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
Run Code Online (Sandbox Code Playgroud)
在Visual Studio中,使用File + Open + File并选择c:\ windows\system32\user32.dll.打开Icon节点,然后双击103.在我的机器上,这是错误图标.返回,右键单击它并选择"导出"将其保存到文件中.
这是不确定的方式.这些图标也可在Visual Studio中使用.从Visual Studio安装目录,导航到Common7\VS2008ImageLibrary\xxxx\VS2008ImageLibrary.zip + VS2008ImageLibrary\Annotations&Buttons\ico_format\WinVista\error.ico.Visual Studio安装中的redist.txt文件直接显式地赋予您在自己的应用程序中使用此图标的权限.
如果默认大小可以的话,您可以使用 .NET 的 SystemIcons 类来完成大约前三个步骤,请参阅modosansreves 答案
所以它可以很简单:
Imaging.CreateBitmapSourceFromHIcon(SystemIcons.Error.Handle)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
45849 次 |
| 最近记录: |