如何更改 WPF 窗口中的标题栏图像? [英] How to change title bar image in WPF Window?
本文介绍了如何更改 WPF 窗口中的标题栏图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何更改 WPF 中的标题栏图像(最左上角的图标)?
How to change the titile bar image (the top-left most icon) in WPF?
推荐答案
Window的Icon属性用于设置窗口的图标.
The Icon attribute of Window is used to set Icon of a window.
<Window x:Class="WindowSample.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="WPF Window Sample" Height="350" Width="525"
Name="FirstWindow" Icon="Icon1.ico" >
Window 类的 Icon 属性表示运行时窗口的图标.此属性采用 ImageSource 变量.
The Icon property of Window class represents a window's icon at run-time. This property takes an ImageSource variable.
以下代码片段使用 BitmapFrame.Create 方法创建 ImageSource 并设置 Window 的 Icon 属性.
The following code snippet uses BitmapFrame.Create method to create an ImageSource and sets the Icon property of a Window.
Uri iconUri = new Uri("pack://application:,,,/Icon1.ico", UriKind.RelativeOrAbsolute);
this.Icon = BitmapFrame.Create(iconUri);
您可以从此处
这篇关于如何更改 WPF 窗口中的标题栏图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文