語言

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 應用程式。

WinUI 3 Gallery 應用程式包含大部分 WinUI 3 控制項、特性和功能的互動式範例。 從 Microsoft Store 取得應用程式,或在 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 搭配 IconSource 時,圖片不會顯示。

<!-- 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,所以可以被分享。

建構函式

名稱 Description
ImageIconSource()

初始化 ImageIconSource 類別的新執行個體。

屬性

名稱 Description
Dispatcher

它總是在 Windows 應用程式 SDK 應用程式中回傳 null 。 改用 DispatcherQueue 。

(繼承來源 DependencyObject)
DispatcherQueue

得到 DispatcherQueue 這個物件所關聯的那個。 代表 DispatcherQueue 一個功能,即使程式碼是由非 UI 執行緒發起,也能存取 UI DependencyObject 執行緒。

(繼承來源 DependencyObject)
Foreground

取得或設定一把畫筆,將控制鍵的前景顏色繪製出來。

(繼承來源 IconSource)
ImageSource

取得或設定影像檔案的 URI 作為圖示來源。

ImageSourceProperty

識別 ImageSource 依賴性質。

方法

名稱 Description
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)

適用於

另請參閱