语言

ImageIconSource 类

定义

表示使用图像类型作为其内容的图标源。

/// [Windows.Foundation.Metadata.ContractVersion(Microsoft.UI.Xaml.XamlContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
/// [Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
class ImageIconSource : IconSource
[Windows.Foundation.Metadata.ContractVersion(typeof(Microsoft.UI.Xaml.XamlContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
[Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
public class ImageIconSource : IconSource
Public Class ImageIconSource
Inherits IconSource
继承
Object IInspectable DependencyObject IconSource ImageIconSource
属性

示例

Important

ImageIconSource 仅限于与某些控件的属性一起使用 IconSource 。 有关详细信息,请参阅“备注”。

Tip

有关详细信息、设计指南和代码示例,请参阅 Icons for Windows apps。

WinUI 3 示例集应用程序包括大多数 WinUI 3 控件、特性和功能的交互式示例。 从 Microsoft 应用商店 获取应用,或在 GitHub 上获取源代码。

以下示例显示了具有 ImageIconSource 的 InfoBar 。 ImageSource 指定应用包中包含的映像。

<InfoBar Title="InfoBar Title"
         Message="This is an InfoBar message." 
         IsOpen="True">
    <InfoBar.IconSource>
        <ImageIconSource ImageSource="ms-appx:///Assets/StoreLogo.png"/>
    </InfoBar.IconSource>
</InfoBar>

下面介绍如何从位图流加载 ImageIconSource。

var bitmapSource = new BitmapSource();
await bitmapSource.SetSourceAsync(bitmapStream);
var icon = new ImageIconSource() { ImageSource = bitmapSource };

注解

ImageIconSource 仅限于使用这些 IconSource 控件的属性:

ImageIconSource 的其他用法不会导致错误,但不会显示图像。 例如,将 ImageIconSource 与 IconSourceElement 一起使用不会显示图像。

<!-- INCORRECT CODE - DO NOT USE -->
<AppBarButton >
    <AppBarButton.Icon>
        <IconSourceElement>
            <ImageIconSource ImageSource="ms-appx:///Assets/StoreLogo.png"/>
        </IconSourceElement>
    </AppBarButton.Icon>
</AppBarButton>
<!-- INCORRECT CODE - DO NOT USE -->

支持的映像类型为 .bmp、.gif、.jpg、.png、.wdp 和 .tiff。

ImageIconSource 类似于 ImageIcon。 但是,由于它不是 FrameworkElement,因此可以共享它。

构造函数

名称 说明
ImageIconSource()

初始化 ImageIconSource 类的新实例。

属性

名称 说明
Dispatcher

始终在 Windows 应用 SDK 应用中返回 null 。 请改用 DispatcherQueue 。

(继承自 DependencyObject)
DispatcherQueue

获取 DispatcherQueue 与此对象关联的对象。 表示 DispatcherQueue 即使代码是由非 UI 线程启动,也可以访问 DependencyObject UI 线程上的设施。

(继承自 DependencyObject)
Foreground

获取或设置绘制控件的前景色的画笔。

(继承自 IconSource)
ImageSource

获取或设置要用作图标源的图像文件的 URI。

ImageSourceProperty

标识 ImageSource 依赖属性。

方法

名称 说明
ClearValue(DependencyProperty)

清除依赖属性的本地值。

(继承自 DependencyObject)
CreateIconElement()

创建图标 UI 元素。

(继承自 IconSource)
CreateIconElementCore()

创建图标 UI 元素。

(继承自 IconSource)
GetAnimationBaseValue(DependencyProperty)

返回为依赖属性建立的任何基值,在动画未处于活动状态的情况下,该属性将适用。

(继承自 DependencyObject)
GetIconElementPropertyCore(DependencyProperty)

将 IconSource 属性映射到 IconElementProperties。

(继承自 IconSource)
GetValue(DependencyProperty)

从 DependencyObject 返回依赖属性的当前有效值。

(继承自 DependencyObject)
ReadLocalValue(DependencyProperty)

如果设置了本地值,则返回依赖属性的本地值。

(继承自 DependencyObject)
RegisterPropertyChangedCallback(DependencyProperty, DependencyPropertyChangedCallback)

注册一个通知函数,用于侦听此 DependencyObject 实例上对特定 DependencyProperty 所做的更改。

(继承自 DependencyObject)
SetValue(DependencyProperty, Object)

设置 DependencyObject 上的依赖属性的本地值。

(继承自 DependencyObject)
UnregisterPropertyChangedCallback(DependencyProperty, Int64)

取消以前通过调用 RegisterPropertyChangedCallback 注册的更改通知。

(继承自 DependencyObject)

适用于

另请参阅