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

Need help with initialization of style/theme, for use with AvaloniaEdit #38

Closed
iksi4prs opened this issue May 14, 2024 · 5 comments
Closed

Comments

@iksi4prs
Copy link

Hi,
I'm using this project for tests, so far with success, and I really like it.
I'm trying to make use of "AvaloniaEdit" control ( https://github.com/AvaloniaUI/AvaloniaEdit ) in my project, but this doesn't seem to work.
The actual result now, is the I see the control in visual-tree and logical-tree of the "F12 debugger", but control itself is not painted/working.

I've checked how it works in a xaml project, and see there is "OnApplyTemplate" inside AvaloniaEdit which is called on start,
when next is called from Main
BuildAvaloniaApp().StartWithClassicDesktopLifetime(args);
and they also mention need to add in xaml:
<StyleInclude Source="avares://AvaloniaEdit/Themes/Fluent/AvaloniaEdit.xaml" />

In the "markup declarative" app, this OnApplyTemplate inside AvaloniaEdit is not called.
To make use of style/theme, I still used the code from example, like here:
https://github.com/AvaloniaUI/Avalonia.Markup.Declarative/blob/master/src/Samples/AvaloniaMarkupSample/App.cs

Any idea what is need to do, to make markup code so that "OnApplyTemplate" will be invoke ?

Thanks for any help

@gritsenko
Copy link
Collaborator

@iksi4prs hey! Can you provide minimal project sample, that I can build locally to reproduce that situation?

@iksi4prs
Copy link
Author

@gritsenko ,
I've put an example here
https://github.com/iksi4prs/Avalonia2

The solution includes 2 apps that uses the "Edit", one with xaml and one with markup,
and all projects compiled with source code instead of nuget so can be debugged.

I'm not sure what is the problem, but when debugging, I've noticed the difference mentioned earlier,
so maybe this is the cause.

see "OnApplyTemplate" in file AvaloniaEdit\TextEditor.cs

The ExampleXaml is based on https://github.com/AvaloniaUI/AvaloniaEdit/tree/master/src/AvaloniaEdit.Demo
(Its basically the same, but resources files used for samples )

Thanks for your help !

@gritsenko
Copy link
Collaborator

Hey @iksi4prs ! I just researched your samples and found that on the xaml example there are following lines in App.xaml

    <FluentTheme />
    <StyleInclude Source="avares://AvaloniaEdit/Themes/Fluent/AvaloniaEdit.xaml" />

the equivalent of them in c# will be following lines in program.cs

            .AfterSetup(b =>
            {
                b.Instance?.Styles.Add(new FluentTheme());
                b.Instance?.Styles.Add((IStyle)AvaloniaXamlLoader.Load(
                        new Uri("avares://AvaloniaEdit/Themes/Fluent/AvaloniaEdit.xaml")));

image

I tried that in your sample and it works now

@iksi4prs
Copy link
Author

iksi4prs commented Jun 9, 2024

Hi @gritsenko , thanks for your help ! works nice.
I really appreciate you took the time to check this.

Next question is more about AvalonEdit, but since you know what the problem was, maybe you have some suggestion how to do it. My knowledge of Avalonia is very basic.

In sake of "future proofing", I thought to add exception in AvalonEdit, in case the theme is not loaded.

Namely in the scenario of someone else adding AvalonEdit to his "Avalonia.Markup.Declarative" project,
and he didn't add the code that you suggested, an exception will be thrown "missing theme... etc".

Do you have any suggestion where to put in in AvalonEdit code, is there a method during initialization where theme should already exist ?

It would be even better if this could be added in code of "Avalonia.Markup.Declarative" itself, so will work with all components that require extre xaml, not just AvalonEdit.
I dont know if its possible.

Thanks again for your help.

@gritsenko
Copy link
Collaborator

I don't think this is critical issue for now. Anyway, you can update your sample with the correct code and add some notes to it into readme file, so it will help in future for those people who will face similar problems in future :-)

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

No branches or pull requests

2 participants