WinUi3 顯示 Icon

在 Windows 11 中內建了 Segoe Fluent Icons 字體,他是預設的小圖示字體,我們可以使用 FontIcon 來顯示 Icon

第一步就是要先尋找想要的 Icon , 開啟 Segoe Fluent Icons font 頁面,找到想要的 Icon 的 Unicode point

以第一個例子來說是 e700 ,在設定 Glyph 屬性時寫為 「&#x」+ 「e700」+ 「;」
    
<FontIcon Glyph="&#xe700;" />
    

筆者在測試時沒有加分號會出錯無法執行

在 Button 上設定 Icon

想要在按鈕上面設定 Icon 可以這樣做:

只有 Icon:
    
<Button>
    <FontIcon Glyph="&#xe700;" />
</Button>
    


按鈕中有文字和 Icon:
    
<Button>
    <StackPanel Orientation="Horizontal">
        <TextBlock Text="選單" Margin="0,0,3,0"/>
        <FontIcon Glyph="&#xe700;" />
    </StackPanel>
</Button>
    




參考資料:
Microsoft.Learn - Segoe Fluent Icons font

留言