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

Current Version of AdonisUI does not work (?) #17

Closed
michel-pi opened this issue Apr 3, 2019 · 8 comments
Closed

Current Version of AdonisUI does not work (?) #17

michel-pi opened this issue Apr 3, 2019 · 8 comments
Labels
bug Something isn't working question Further information is requested

Comments

@michel-pi
Copy link

Hey.

The problem here is that the newest version of AdonisUI does not seem to work correctly in different projects. I also tested version 1.6 which seems to work correctly.

Also a side note that i noticed that my fonts seem to be always bold when i use AdonisUI.
I dont know if this is intended because i did not had enough time testing this UI framework.

The issues i got when starting with a new project are

  • The Application resources seem to have a warning attached to them that they are null
  • The XAML Designer does not display the theme and only renders a transparent background with standard controls

When creating a new window in an existing application i got the following issues

  • TextBox & Checkboxes can not be used because they throw an exception from the SpaceExtensions
  • Different other exceptions when using TextBox or CheckBox and not assigning the Text or IsChecked property in xaml
  • example AdonisTest.zip

I of course followed the examples and the instructions given in this repository.

Thank you for your time :)

@nkristek
Copy link
Collaborator

nkristek commented Apr 3, 2019

It seems that there was no App.xaml file generated as is default when creating an application using the WPF application template in Visual Studio.
Try creating a WPF application from New Project > Visual C# > Windows Desktop > WPF App (.NET Framework).
You see that there will be files called App.xaml and App.xaml.cs. Now you need to include the AdonisUI styles so your App.xaml file looks like:

<Application x:Class="WpfApp1.App"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:adonisUi="clr-namespace:AdonisUI;assembly=AdonisUI"
             StartupUri="MainWindow.xaml">
    <Application.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>

                <ResourceDictionary Source="{x:Static adonisUi:ResourceLocator.LightColorScheme}"/>
                <ResourceDictionary Source="{x:Static adonisUi:ResourceLocator.ClassicTheme}"/>

            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </Application.Resources>
</Application>

App.xaml.cs offers methods like OnStartup() where you can create you own Window. If you do create you own window you should remove the StartupUri tag from you App.xaml.

If you want to see another example application, I'm currently developing one called Stein.

@nkristek
Copy link
Collaborator

nkristek commented Apr 3, 2019

In your case, the NullReferenceException is thrown because Application.Current is null.
I just copied your MainWindow.xaml and MainWindow.xaml.cs inside a project created using the WPF App template (with App.xaml and App.xaml.cs files) and uncommenting the TextBox etc. controls didn't throw that exception.

@benruehl
Copy link
Owner

benruehl commented Apr 3, 2019

I agree with @nkristek . Is there a reason why you created the Program.cs file yourself instead of using the default App.xaml.cs file? By default, the startup project in a WPF application contains a class that inherits from System.Windows.Application. It does not implement the Main() method but instead uses lifecycle methods like OnStartup() to run custom startup code. This might help as a starting point

Regarding the warnings you receive in your resources, I can only say that they disappear as soon as I deactivate the XAML Designer. Unfortunately, the designer sometimes shows errors or warnings which are not real (much too often if you ask me). In the past I was not able to resolve those warnings but I am not willing to give up fancy features just because the designer is broken :). If someone comes up with a solution that fixes the warnings but does not involve a change of AdonisUI's interface, I will include it as well. Until then, you might have to live with the warnings, disable the XAML Designer or hope for fixes from Microsoft.

The bold font you receive is set by the default style of Label and is by design. Labels are meant to be placed next to input controls like TextBox for example as a caption of their purpose. If you just want to display text, use TextBlock instead and you won't have bold font weight.

I hope this addresses all your issues. Please let me know if you have further questions.

@benruehl benruehl added the question Further information is requested label Apr 3, 2019
@michel-pi
Copy link
Author

Thank you for your detailed answers but i guess you misunderstood this a bit.
I know how to create WPF windows and i understand how i can create a new project with the wpf template 😄

I tried the normal WPF project structure and it did not work. (using the information given by the readme and the demo project).

I uploaded the other project to show how others may implement a single AdonisUI window into their otherwise console, winforms or "another framework" wpf application.
I think this way should be supported and as it turns out it was in version 1.6 of AdonisUI where this "weird" way and the standard way worked fine even with the designer.

And i think you should think more about the designer instead of just avoiding it. It gives a great preview on what you are doing in xaml right now. I guess no one is really using the drag and drop gui features here.

@benruehl
Copy link
Owner

benruehl commented Apr 4, 2019

Ok now I understand your use case of creating a WPF window in a non-WPF application. I will add a null check in the SpaceExtension to avoid the crash. But that will make some controls missing their default values for padding as the application resources cannot be retrieved. I will see if I find a different way to get the resources in case Application.Current ist null. The SpaceExtension ist part of the library since v1.8 so that might be the reason why v1.6 does not cause problems for you.

You say you created your application the normal way first, but that didn't work either. So what did not work there? I know of at least 3 applications (plus the AdonisUI demo app) that use the current version and all of them work fine. Could you send a version of your project which does not work for you having the normal structure so we can investigate further?

The XAML Designer works for me at least in normal WPF applications. It shows previews of views and applies AdonisUI's styles as it should (although they look a bit different than during runtime). It just display warnings saying that it cannot resolve resources which I don't know how to fix. Is that different for you?

@benruehl benruehl added the bug Something isn't working label Apr 4, 2019
@michel-pi
Copy link
Author

michel-pi commented Apr 4, 2019

The normal application "works" when your definition of working is that errors in "design time" and a not correctly displaying designer are okay. (dont take that wrong 😃)

Disclaimer: i get the normal wpf style in my designer. Did i mention that i am using Visual Studio 2017?
The transparent background issue in the designer was caused by setting the background brush to something from adonisui.

Errors (i removed some of the auto generated lines to make it a bit shorter):
Application -> Object reference not set to an instance of an object

<Application 
             xmlns:adonisUi="clr-namespace:AdonisUI;assembly=AdonisUI"
             StartupUri="MainWindow.xaml">
    <Application.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="pack://application:,,,/AdonisUI;component/ColorSchemes/Dark.xaml"/>
                <ResourceDictionary Source="pack://application:,,,/AdonisUI.ClassicTheme;component/Resources.xaml"/>
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </Application.Resources>
</Application>

ResourceDictionary Source="{x:Static adonisUi:ResourceLocator.DarkColorScheme}"/> -> Value can not be null. Parameter name: item

<Application 
             xmlns:adonisUi="clr-namespace:AdonisUI;assembly=AdonisUI"
             StartupUri="MainWindow.xaml">
    <Application.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="{x:Static adonisUi:ResourceLocator.DarkColorScheme}"/>
                <ResourceDictionary Source="{x:Static adonisUi:ResourceLocator.ClassicTheme}" />
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </Application.Resources>
</Application>

I am doing nothing else than creating a new WPF application using visual studio, downloading both Adonis NuGet packages, writing the ResourceDictionary stuff into the App.xaml file and adding

<Window.Style>
        <Style TargetType="Window" BasedOn="{StaticResource {x:Type Window}}"/>
</Window.Style>

to the MainWindow.xaml

Even if it compiles that way it's not really good that way.


In regards to the other issue when using a non standard wpf window:
All other Menu frameworks i used so far (and the most popular MahApps.Metro) worked fine that way.
I dont know much about this topic but it would be nice if this behaviour could be fixed without any drawbacks in the designer or solution.


i am hoping to see these things fixed in the future because i really liked this one and i want to use it more
👍

@benruehl
Copy link
Owner

benruehl commented Apr 4, 2019

I tweaked the SpaceExtension a little. You might checkout the branch hotfix/spaceextension and verify if it works for you. I tested it with your project already but another pair of eyes won't hurt.

Now you have the option to specify a place where the AdonisUI resources live instead of Application.Current. That is required in your case and looks like the following code. It is important to set the reference before calling InitializeComponent(); because this evaluates the XAML code which will throw errors again in case the SpaceExtension does not find any access to the resources.

public MainWindow()
{
    AdonisUI.SpaceExtension.SetSpaceResourceOwnerFallback(this);

    InitializeComponent();

    this.MouseLeftButtonDown += (object sender, MouseButtonEventArgs e) => DragMove();
}

Hope this helps.

@michel-pi
Copy link
Author

Thank you for your quick workarround.

I will also take a look on how other ui frameworks handle this and will report back if i find a better solution.

benruehl added a commit that referenced this issue Apr 11, 2019
Fix rare Exceptions in SpaceExtension regarding #17 and #19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants