iNKORE-NET / UI.WPF.Modern

Modern (Fluent 2) styles and controls for your WPF applications
GNU Lesser General Public License v2.1
447 stars 39 forks source link

No App xml error #49

Open pp111 opened 7 months ago

pp111 commented 7 months ago

I need to use the library without an App.xaml

I used the sample project NoAppXaml as a reference. So the library resources are added in Window.Resources

The sample works fine, however if I add a NavigationView to the sample project window the application crashes with a NullReferenceException at

iNKORE.UI.WPF.Converters.CornerRadiusFilterConverter.Convert(object, System.Type, object, System.Globalization.CultureInfo)

This is the modified MainWindow.xaml that makes the application to crash:

<Window x:Class="NoAppXamlTest.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:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:ui="http://schemas.inkore.net/lib/ui/wpf/modern"
        xmlns:local="clr-namespace:NoAppXamlTest"
        mc:Ignorable="d"
        Title="MainWindow" Height="450" Width="800">
    <Window.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ui:ThemeResources/>
                <ui:XamlControlsResources/>
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </Window.Resources>
    <StackPanel>
        <ui:NavigationView
            x:Name="navigation1"
            Height="460"
            Header="This is Header Text"
            IsBackButtonVisible="Collapsed"
            IsFooterSeparatorVisible="True"
            IsSettingsVisible="False"
            IsTabStop="False"
            PaneDisplayMode="Top"
            >
        </ui:NavigationView>
        <Button Content="test" VerticalAlignment="Top" HorizontalAlignment="Left"/>
        <CheckBox/>
    </StackPanel>
</Window>

It seems that some resources (CornerRadius) are not loaded, but I can't guess where is the problem.

whitesong1 commented 7 months ago

I also encountered the same problem.

I want use many ui lib in my project so I don't want all pages to be overwritten with default styles by a certain library.

but i will get the error "Object reference not set to an instance of an object."when i use the navigation control . and if i join the code" " to app.xaml, the error will be disappear.

this is my code:

error:

<Application x:Class="*.App"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:local="clr-namespace:*"
             Startup="Application_Startup">

    <Application.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="./Style/Shell/ShellStyle.xaml" />
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </Application.Resources>
</Application>

<Window x:Class="*.Shell"
        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:ink="http://schemas.inkore.net/lib/ui/wpf/modern"
        xmlns:local="clr-namespace:*"
        xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        Title="Shell"
        Width="1080"
        Height="650"
        d:DataContext="{d:DesignInstance Type=local:ShellViewModel,
                                         IsDesignTimeCreatable=True}"
        Background="#F3F3F3"
        mc:Ignorable="d">
    <Window.Resources>
    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Light.xaml" />
            <ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.CheckBox.xaml" />
            <ResourceDictionary Source="pack://application:,,,/MaterialDesignColors;component/Themes/Recommended/Primary/MaterialDesignColor.DeepPurple.xaml" />
            <ResourceDictionary Source="pack://application:,,,/ClouldMusic.Shell;component/Dictionary/ShellDictionary.xaml" />
            <ink:ThemeResources />
            <ink:XamlControlsResources />
        </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>
</Window.Resources>

    <Grid>
 >>       <ink:NavigationView />
    </Grid>
</Window>

I don`t konw how to slove the question.

NotYoojun commented 6 months ago

It seems that conflicts may happen when using multiple ui libraries at the same time.

Sadly, the solution may vary when you are using different ui libraries. I'm in the weeds these days for web development and have no time to look into this.

We tried something to fix the null reference exception. But the results you provided proved my fix didn't work, I have no idea why.