WPF - WPFUI 库 - 图标不会在导航栏上呈现 C#

问题描述 投票:0回答:1

我正在使用 WPFUI 的演示模板来开发 WPF 应用程序,同时将新项目编辑到导航栏列表中,图标无法正确呈现,直到您将鼠标悬停在图片中,我无法找到什么导致这个错误

项目设置:

  • WPF .NET 7
  • WPF-UI(3.0.0-预览4)
  • 社区工具包.Mvvm (8.2.1)

这是我的代码:

MainWindow.xaml

<ui:FluentWindow
  x:Class="wpfuiImpal.Views.Windows.MainWindow"
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
  xmlns:local="clr-namespace:wpfuiImpal.Views.Windows"
  xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
  xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml"
  Title="{Binding ViewModel.ApplicationTitle, Mode=OneWay}"
  Width="1280"
  Height="720"
  d:DataContext="{d:DesignInstance local:MainWindow,
                                   IsDesignTimeCreatable=True}"
  d:DesignHeight="1280"
  d:DesignWidth="720"
  ui:Design.Background="{DynamicResource ApplicationBackgroundBrush}"
  ui:Design.Foreground="{DynamicResource TextFillColorPrimaryBrush}"
  ExtendsContentIntoTitleBar="True"
  Foreground="{DynamicResource TextFillColorPrimaryBrush}"
  WindowBackdropType="Mica"
  WindowCornerPreference="Round"
  WindowStartupLocation="CenterScreen"
  mc:Ignorable="d">
  <Grid>
      <ui:TitleBar
          x:Name="TitleBar"
          Title="{Binding ViewModel.ApplicationTitle}"
          Grid.Row="0"
          CloseWindowByDoubleClickOnIcon="True">
          <ui:TitleBar.Icon>
              <ui:ImageIcon Source="pack://application:,,,/Assets/wpfui-icon-256.png" />
          </ui:TitleBar.Icon>
      </ui:TitleBar>

      <ui:NavigationView
          x:Name="NavigationView"
          Padding="40,0,40,0"
          BreadcrumbBar="{Binding ElementName=BreadcrumbBar}"
          FooterMenuItemsSource="{Binding ViewModel.FooterMenuItems, Mode=OneWay}"
          FrameMargin="1"
          IsBackButtonVisible="Visible"
          IsPaneToggleVisible="True"
          MenuItemsSource="{Binding ViewModel.MenuItems, Mode=OneWay}"
          OpenPaneLength="350"
          PaneDisplayMode="Left"
          TitleBar="{Binding ElementName=TitleBar, Mode=OneWay}">
          <ui:NavigationView.Header>
              <ui:BreadcrumbBar x:Name="BreadcrumbBar" Margin="40,32,40,20" />
          </ui:NavigationView.Header>
          <ui:NavigationView.ContentOverlay>
              <Grid>
                  <ui:SnackbarPresenter x:Name="SnackbarPresenter" />
              </Grid>
          </ui:NavigationView.ContentOverlay>
      </ui:NavigationView>

      <ContentPresenter x:Name="RootContentDialog" Grid.Row="0" />
  </Grid>
</ui:FluentWindow>

MainWindow.xaml.cs

// This Source Code Form is subject to the terms of the MIT License.
// If a copy of the MIT was not distributed with this file, You can obtain one at https://opensource.org/licenses/MIT.
// Copyright (C) Leszek Pomianowski and WPF UI Contributors.
// All Rights Reserved.

using wpfuiImpal.ViewModels.Windows;

namespace wpfuiImpal.Views.Windows;

public partial class MainWindow
{
    public MainWindowViewModel ViewModel { get; }

    public MainWindow(
        MainWindowViewModel viewModel,
        INavigationService navigationService,
        IServiceProvider serviceProvider,
        ISnackbarService snackbarService,
        IContentDialogService contentDialogService
    )
    {
        Wpf.Ui.Appearance.Watcher.Watch(this);

        ViewModel = viewModel;
        DataContext = this;

        InitializeComponent();

        navigationService.SetNavigationControl(NavigationView);
        snackbarService.SetSnackbarPresenter(SnackbarPresenter);
        contentDialogService.SetContentPresenter(RootContentDialog);

        NavigationView.SetServiceProvider(serviceProvider);
        
    }
}

MainWindowViewModel.cs

// This Source Code Form is subject to the terms of the MIT License.
// If a copy of the MIT was not distributed with this file, You can obtain one at https://opensource.org/licenses/MIT.
// Copyright (C) Leszek Pomianowski and WPF UI Contributors.
// All Rights Reserved.

using System.Collections.ObjectModel;
using Wpf.Ui.Common;
using Wpf.Ui.Controls;

namespace wpfuiImpal.ViewModels.Windows;

public partial class MainWindowViewModel : ObservableObject
{
    [ObservableProperty]
    private string _applicationTitle = "IMPAL - ACOPIO";

    [ObservableProperty]
    private ObservableCollection<object> _menuItems = new()
    {
        new NavigationViewItem()
        {
            Content = "MENU PRINCIPAL",
            Icon = new SymbolIcon { Symbol = SymbolRegular.Home24 },
            TargetPageType = typeof(Views.Pages.DashboardPage)
        },
        new NavigationViewItem()
        {
            Content = "LISTA CHOFERES",
            Icon = new SymbolIcon { Symbol = SymbolRegular.ClipboardTaskListLtr24 },
            TargetPageType = typeof(Views.Pages.ChoferDataPage)
        },
        new NavigationViewItem()
        {
            Content = "LISTA VEHICULOS",
            Icon = new SymbolIcon { Symbol = SymbolRegular.ClipboardTaskListLtr24 },
            TargetPageType = typeof(Views.Pages.VehiculoDataPage)
        },
        new NavigationViewItem()
        {
            Content = "LISTA EMPRESAS",
            Icon = new SymbolIcon { Symbol = SymbolRegular.ClipboardTaskListLtr24 },
            TargetPageType = typeof(Views.Pages.GenEmpresaDataPage)
        },
        new NavigationViewItem()
        {
            Content = "LISTA DE PRODUCTO / CALIFICACION",
            Icon = new SymbolIcon { Symbol = SymbolRegular.Notepad24 },
            TargetPageType = typeof(Views.Pages.ProductoCalificacion)
        },
        new NavigationViewItem()
        {
            Content = "REGISTRO PESAJE",
            Icon = new SymbolIcon { Symbol = SymbolRegular.Notepad24 },
            TargetPageType = typeof(Views.Pages.RegistroPesaje)
        },
        new NavigationViewItem()
        {
            Content = "RECEPCION PRODUCTO",
            Icon = new SymbolIcon { Symbol = SymbolRegular.Notepad24 },
            TargetPageType = typeof(Views.Pages.RecepcionProductoDataPage)
        },
        new NavigationViewItem()
        {
            Content = "REMISION GRANOS",
            Icon = new SymbolIcon { Symbol = SymbolRegular.Notepad24 },
            TargetPageType = typeof(Views.Pages.RemisionGranosDataPage)
        }
    };

    [ObservableProperty]
    private ObservableCollection<object> _footerMenuItems = new()
    {
        new NavigationViewItem()
        {
            Content = "CONFIGURACION",
            Icon = new SymbolIcon { Symbol = SymbolRegular.Settings24 },
            TargetPageType = typeof(Views.Pages.SettingsPage)
        }
    };

    [ObservableProperty]
    private ObservableCollection<MenuItem> _trayMenuItems = new()
    {
        new MenuItem { Header = "MENU", Tag = "tray_home" }
    };
}
c# wpf xaml wpf-controls
1个回答
0
投票

我发现了问题,这两行代码在图标上加载颜色导致了问题,并且删除或更改 app.xaml 中的颜色解决了问题

  ui:Design.Background="{DynamicResource ApplicationBackgroundBrush}"
  ui:Design.Foreground="{DynamicResource TextFillColorPrimaryBrush}"
© www.soinside.com 2019 - 2024. All rights reserved.