gpt4 book ai didi

WPF - WPFUI Library - Icons doesn't render on the Navigation bar C#(WPF-WPFUI库-图标不呈现在导航栏C#上)

转载 作者:bug小助手 更新时间:2023-10-24 20:20:13 34 4
gpt4 key购买 nike



I am using a demo template from WPFUI for developing a WPF App while editing new items to the list for the navigation bar the icons don't render properly until you hover with the mouse like in the picture and I am not able to find what is causing this error

我正在使用来自WPFUI的演示模板来开发WPF应用程序,同时编辑导航栏的列表中的新项目图标不会正确呈现,直到您像图片中那样用鼠标悬停,我无法找到导致此错误的原因


Icons doesn't render until mouse hover the item list of navigation bar


Project Setup:

项目设置:



  • WPF .NET 7

  • WPF-UI (3.0.0-preview4)

  • CommunityToolkit.Mvvm (8.2.1)


Here is my code:

以下是我的代码:


MainWindow.xaml

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

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

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" }
};
}

更多回答
优秀答案推荐

I found the issue, these 2 lines of code were loading colors over the icons making the issue, and removing or changing the color in app.xaml fixed the issue

我发现了这个问题,这两行代码在制造问题的图标上加载颜色,并在应用程序中删除或更改颜色。xaml修复了这个问题


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

更多回答

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com