ImageIconSource 类

定义

表示使用图像类型作为其内容的图标源。 当前支持的映像类型包括 .bmp、.gif、.jpg、.png、.wdp 和 .tiff。

/// [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
属性

示例

提示

有关详细信息、设计指南和代码示例,请参阅 Windows 应用的图标

WinUI 3 库应用包括大多数 WinUI 3 控件、特性和功能的交互式示例。 通过 Microsoft Store 获取应用,或在 GitHub 上获取源代码。

以下示例演示具有 ImageIconSource 的 AppBarButtonImageSource 指定应用包中包含的映像。

<!--
xmlns:muxc="using:Microsoft.UI.Xaml.Controls"
-->

<AppBarButton >
    <AppBarButton.Icon>
        <IconSourceElement>
            <muxc:ImageIconSource ImageSource="ms-appx:///Assets/globe.png"/>
        </IconSourceElement>
    </AppBarButton.Icon>
</AppBarButton>

下面演示如何从位图流加载 ImageIconSource。

// using muxc = Microsoft.UI.Xaml.Controls;

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

注解

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

构造函数

ImageIconSource()

初始化 ImageIconSource 类的新实例。

属性

Dispatcher

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

(继承自 DependencyObject)
DispatcherQueue

获取 DispatcherQueue 与此 对象关联的 。 DispatcherQueue表示可以访问 DependencyObject UI 线程上的 的功能,即使代码是由非 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)

适用于

另请参阅