Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve Performance and Simplify Xaml Resources #22

Closed
ghost1372 opened this issue Nov 26, 2023 · 19 comments · Fixed by #27
Closed

Improve Performance and Simplify Xaml Resources #22

ghost1372 opened this issue Nov 26, 2023 · 19 comments · Fixed by #27
Labels
enhancement New feature or request

Comments

@ghost1372
Copy link
Contributor

ghost1372 commented Nov 26, 2023

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
Copy link
Contributor Author

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
Copy link
Member

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

Will this tool cause any extra references?

@ghost1372
Copy link
Contributor Author

ghost1372 commented Nov 27, 2023

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
Copy link
Member

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
Copy link
Contributor Author

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 NotYoojun added the enhancement New feature or request label Nov 30, 2023
@NotYoojun
Copy link
Member

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

@ghost1372
Copy link
Contributor Author

Tnx

@NotYoojun
Copy link
Member

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

@ghost1372
Copy link
Contributor Author

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

yes, no problem

@ghost1372
Copy link
Contributor Author

ghost1372 commented Nov 30, 2023

@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
Copy link
Member

Okay I've merged it

@ghost1372
Copy link
Contributor Author

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 NotYoojun reopened this Dec 1, 2023
@NotYoojun
Copy link
Member

NotYoojun commented Dec 1, 2023

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
Copy link
Member

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
Copy link
Member

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
Copy link
Contributor Author

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

@ghost1372
Copy link
Contributor Author

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

@NotYoojun
Copy link
Member

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!

@NotYoojun NotYoojun closed this as not planned Won't fix, can't repro, duplicate, stale Dec 2, 2023
@ghost1372
Copy link
Contributor Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants