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

t98cgbkg  于 2023-10-14  发布在  C#
关注(0)|答案(1)|浏览(218)

我正在使用一个演示模板从WPFUI开发一个WPF应用程序,同时编辑新的项目列表的导航栏的图标不正确渲染,直到你用鼠标悬停像在图片中,我无法找到是什么原因导致这个错误

项目设置:

  • WPF .NET 7
  • WPF-UI(3.0.0-预览版4)
  • CommunityToolkit.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" }
    };
}
v09wglhw

v09wglhw1#

我发现了这个问题,这2行代码加载颜色的图标,使问题,并删除或改变颜色的app.xaml修复了这个问题

ui:Design.Background="{DynamicResource ApplicationBackgroundBrush}"
  ui:Design.Foreground="{DynamicResource TextFillColorPrimaryBrush}"

相关问题