[英]Custom image on navigation view item control does not display at run time
我創建了一個 Windows Template Studio (Universal Windows(UWP)) C# 項目,應用導航窗格項目類型,使用 MVVM 基本設計模式,有幾個頁面可以導航。 我已將 NavigationViewItem 上的默認圖標替換為自定義圖像。 但是,即使在設計時顯示帶有文本的自定義圖像,在運行時也只顯示文本而不顯示自定義圖像。
當我嘗試刪除“x:Uid”(我相信它也被 Resources.resw 文件使用)時,將顯示帶有文本的自定義圖像,但是,當單擊 NavigationViewItem 控件時,程序停止/崩潰(在 App .gics 文件):
#if DEBUG && !DISABLE_XAML_GENERATED_BREAK_ON_UNHANDLED_EXCEPTION
UnhandledException += (sender, e) =>
{
if (global::System.Diagnostics.Debugger.IsAttached) global::System.Diagnostics.Debugger.Break();
};
#endif
這是xaml代碼:
<winui:NavigationViewItem x:Uid="Shell_AttentionList" helpers:NavHelper.NavigateTo="views:AttentionListPage" Height="75">
<winui:NavigationViewItem.Content>
<StackPanel Orientation="Horizontal">
<Image Source="/Images/attentionList.png" />
<TextBlock Text=" Attention List" FontSize="16" FontFamily="segoe ui" VerticalAlignment="Center" HorizontalAlignment="Left"/>
</StackPanel>
</winui:NavigationViewItem.Content>
</winui:NavigationViewItem>
謝謝
你可以試試這個——
使用 StackPanel [不推薦]
<NavigationViewItem>
<StackPanel Orientation="Horizontal">
<Image Height="50"
Margin="5"
Source="Assets/bus.png"
Stretch="Uniform"/>
<TextBlock Text="Sample Text"/>
</StackPanel>
</NavigationViewItem>
使用 BitmapIcon [推薦]
<NavigationViewItem Content="Sample Text" >
<NavigationViewItem.Icon>
<BitmapIcon UriSource="ms-appx:///Assets/bus.png"/>
</NavigationViewItem.Icon>
</NavigationViewItem>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.