iNKORE-NET / UI.WPF.Modern

Modern (Fluent 2) styles and controls for your WPF applications
https://docs.inkore.net/ui-wpf-modern
GNU Lesser General Public License v2.1
326 stars 29 forks source link

Improve Performance and Simplify Xaml Resources #22

Closed ghost1372 closed 7 months ago

ghost1372 commented 7 months ago

we can improve Performance and simplify Xaml Resources, I did this for HandyControl and it can improves performance and simplify development and xaml resources. in WPF We must have only one resource file (containing all resources a single very very large file), otherwise we will suffer from performance loss. Since it is very difficult to develop the app in only one xaml file, we use MergedDictionary and seperated files. But what if we use separate files but collect them all in one file? In this case, we have made the development process easier and improved the performance.

we can use a tool called: XAMLTools.MSBuild if you want I can do this and collect all the resources in one file. for this we need to move xaml files in one places, so project structure will be change let me know if you are agree or not

ghost1372 commented 7 months ago

by using this tool this kind of refrences will be gone and we dont need them anymore

<ResourceDictionary.MergedDictionaries>
        <ResourceDictionary Source="/iNKORE.UI.WPF.Modern;component/Themes/Styles/Button.xaml" />
        <ResourceDictionary Source="/iNKORE.UI.WPF.Modern;component/Themes/Styles/TextBox.xaml" />
    </ResourceDictionary.MergedDictionaries>

<ResourceDictionary.MergedDictionaries>
        <ResourceDictionary Source="Button.xaml" />
        <ResourceDictionary>
            <converters:RoundMathConverter x:Key="RoundMathConverter" />
            <converters:RoundRadiusConverter x:Key="RoundRadiusConverter" />
        </ResourceDictionary>
    </ResourceDictionary.MergedDictionaries>
NotYoojun commented 7 months ago

Sorry, I can't rly understand what u said. Could you be more specific?

Will this tool cause any extra references?

ghost1372 commented 7 months ago

Sorry, I can't rly understand what u said. Could you be more specific?

Will this tool cause any extra references?

This is a msbuild tasks so there is no dll or dependency.

XAMLTools.MSBuild Combines multiple XAML files to one large file. This is useful when you want to provide one Generic.xaml instead of multiple small XAML files. Using one large XAML file not only makes it easier to consume, but can also drastically improving loading performance.

Currently, you are referencing converters and styles in each resource dictionary And you also reference the resource dictionaries as a MergedDictionary.

We can delete all dictionaries and references, this tool can help us read all xaml files exist in our repo and make a single xaml file which contains all our resources/styles this way app will be run faster and style loading will be improved

NotYoojun commented 7 months ago

Some dictionaries are dynamically called, like Light.xaml and Dark.xaml and so on. I'm not sure it can work on this. However maybe you can have a try.

Btw how will it change the project structure?

ghost1372 commented 7 months ago

Some dictionaries are dynamically called, like Light.xaml and Dark.xaml and so on. I'm not sure it can work on this. However maybe you can have a try.

Btw how will it change the project structure?

Schema will be excluded from merging in a single file. we only merge styles and custom controls and other stuffs like converters... we can use current structure, but we can make things better, for example we can create a xaml file for Converters, moving all custom control styles in a Folder currently they are seperated in each folder (NavigationView\NavigationView.xaml , InfoBar\InfoBar.xaml)

otherwise we should use a list of exclude options...

NotYoojun commented 7 months ago

Pls wait for me to re-organize the Modern.Controls library structure, then you can have a try

ghost1372 commented 7 months ago

Tnx

NotYoojun commented 7 months ago

I think it's wiser to keepn the current folder structure. Can you do that with the folder structure unchanged?

ghost1372 commented 7 months ago

I think it's wiser to keepn the current folder structure. Can you do that with the folder structure unchanged?

yes, no problem

ghost1372 commented 7 months ago

@NotYoojun I was able to successfully merge the resources😁 However, there is a problem that prevents it from merging!

FontIcon.cs (FontFamily)UIApplication.Current.FindResource("SymbolThemeFontFamily"), changing this line to new FontFamily("Segoe MDL2 Assets"), can fix this issue

--

also we can use like this:

new FontFamily("Segoe Fluent Icons,Segoe MDL2 Assets,Segoe UI Symbol")

NotYoojun commented 7 months ago

Okay I've merged it

ghost1372 commented 7 months ago

i created a pr #27 which covers iNKORE.UI.WPF.Modern, and i am waiting for you to re-organize iNKORE.UI.WPF.Modern.Controls

NotYoojun commented 7 months ago

Hi! Sorry to bother you, but there's still an exception keeping throwed. Can you have a minute to check it out? Fyi, the latest nuget package also has this issue and doesn't work.

I tried to remove the merged reference in MenuFlyout.xaml, but that doesn't work, either.

image
NotYoojun commented 7 months ago

Hey @ghost1372 ,I think the current structure of iNKORE.UI.WPF.Modern.Controls is okay and I'm not gonna touch it. You can start it any minute you want.

NotYoojun commented 7 months ago

Hi! Sorry to bother you, but there's still an exception keeping throwed. Can you have a minute to check it out? Fyi, the latest nuget package also has this issue and doesn't work.

I tried to remove the merged reference in MenuFlyout.xaml, but that doesn't work, either.

This issue only occurs only when the config is set to Release

ghost1372 commented 7 months ago

@NotYoojun i dont know why but changing refrence to CombinedResources.xaml fixed bug.

29

ghost1372 commented 7 months ago

I strongly suggest that you merge the libraries into a Single Library

NotYoojun commented 7 months ago

Thank you so much for working with us these days. So sorry that these don't work. I hope we can collaborate more in the future!

ghost1372 commented 7 months ago

Thank you so much for working with us these days. So sorry that these don't work. I hope we can collaborate more in the future!

Thank you I enjoyed it during this time👌 I found out more information about merging and will work on it. But I will not be hasty like this time and I will test completely. I have reported some bugs to XamlTools and they have been fixed. Therefore, we may have another chance in this field. I will let you know when I get the result.