Sybaris
Topic Author
Posts: 39
Joined: 21 Feb 2019, 10:13

Styling and behaviour of MenuItems

29 Mar 2021, 12:03

Hello everybody,

I'm trying to style menus and menu items.

In App.xaml I defined a style for menu items:
<Style TargetType="{x:Type MenuItem}">
            <Setter Property="Background" Value="#D3D3D3" />
            <Setter Property="Foreground" Value="Magenta" />
 </Style>
I would now expect that all menu items have a gray background and a magenta foreground. But under Unity everything stays unchanged...
I have the WPF version in parellel to the Unity version and there everything works as expected.

EDIT: When I put the style definitions in the resources section of the corresponding user control, then it seems to work.
So Noesis GUI is obviously not merging the App.xaml part into the other XAML files. What do I have to do to make the definitions in App.xaml available to all other XAML files, as it is under WPF?
The idea of App.xaml is that I have to define global styles and templates only once...

Another issue: Noesis GUI seems to have a kind of focus/mouse over handling for menus. When I move the mouse away from the menu, that whole menu changes colors.
Is this "by design"? WPF doesn't have a specific "focus/mouse over handling" for menus AFAIK.

Last question: where are the Noesis GUI default styles and templates located?

I'm using Version 2.1.0f1.

Thanks in advance!

Günther

btw: would it be too much to ask for a simpe way to attach images to posts? Having to insert an URL means that I have to upload every single image to a host...
 
Sybaris
Topic Author
Posts: 39
Joined: 21 Feb 2019, 10:13

Re: Styling and behaviour of MenuItems

29 Mar 2021, 20:04

OK, to one of my questions I found the answer myself. App.xaml is not used when using the project template. (Why is it there then?)
The XAML that plays the role of the App.xaml under WPF has to be set in the Noesis settings panel. To stay consistent with WPF it's better to manually include it in every XAML file via a MergedDictionaries tag.

The other questions are still "pending".
 
User avatar
sfernandez
Site Admin
Posts: 2984
Joined: 22 Dec 2011, 19:20

Re: Styling and behaviour of MenuItems

30 Mar 2021, 11:57

Hi,
So Noesis GUI is obviously not merging the App.xaml part into the other XAML files. What do I have to do to make the definitions in App.xaml available to all other XAML files, as it is under WPF?
Using the Application Resources in Unity is the recommended way of sharing the styles and resources for the whole application. You should create a ResourceDictionary with all your styles and then include it in App.xaml for Blend, and in Noesis Settings for Unity to get the same results.

App.xaml (Blend)
<Application x:Class="UnityApp1.App"
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  StartupUri="/UnityApp1;component/UnityApp1/Assets/MainWindow.xaml">
  <Application.Resources>
    <ResourceDictionary>
      <ResourceDictionary.MergedDictionaries>
        <ResourceDictionary Source="/Noesis.GUI.Extensions;component/Theme/NoesisTheme.LightBlue.xaml"/>
        <ResourceDictionary Source="/UnityApp1;component/UnityApp1/Assets/Theme.xaml"/>
      </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>
  </Application.Resources>
</Application>
ApplicationResources.xaml (set in Unity's NoesisSettings)
<ResourceDictionary
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
  <ResourceDictionary.MergedDictionaries>
    <ResourceDictionary Source="NoesisGUI/Theme/NoesisTheme.LightBlue.xaml"/>
    <ResourceDictionary Source="Theme.xaml"/>
  </ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
To stay consistent with WPF it's better to manually include it in every XAML file via a MergedDictionaries tag.
This is not a good idea because you will end loading the same ResourceDictionary xaml for each xaml.
I would now expect that all menu items have a gray background and a magenta foreground. But under Unity everything stays unchanged...
As explained in our Styles and Templates tutorial, you have to provide a Theme with default styles and templates for the controls used in your application (you can use our NoesisTheme or create your own). And when defining local styles you have to use BasedOn property to extend application styles (so the rest of properties from the theme, like Template, are still applied). Following with previous example, in your Theme.xaml you should define your MenuItem style like this to extend the definition in NoesisTheme:
<Style TargetType="{x:Type MenuItem}" BasedOn="{StaticResource {x:Type MenuItem}}">
  <Setter Property="Background" Value="#D3D3D3" />
  <Setter Property="Foreground" Value="Magenta" />
</Style>
Noesis GUI seems to have a kind of focus/mouse over handling for menus. When I move the mouse away from the menu, that whole menu changes colors.
Is this "by design"? WPF doesn't have a specific "focus/mouse over handling" for menus AFAIK.
Maybe I don't understand the question but I only see the MenuItem changing its color when it has its mouse over, and the same occurs in WPF. It is the visual state associated when its IsHightlighted property is set to true.
where are the Noesis GUI default styles and templates located?
I'm using Version 2.1.0f1.
In that version Noesis theme with default styles and templates was embedded in the library but I attached it here in case you need it as reference.
NoesisTheme.zip
NoesisTheme 2.1
(12.94 KiB) Downloaded 75 times

Anyway, I recommend you upgrade to NoesisGUI 3.0 so you can benefit from latest features and a more modern theme:
NoesisTheme.png
would it be too much to ask for a simpe way to attach images to posts? Having to insert an URL means that I have to upload every single image to a host...
You can attach a png file, and then place it inline (as I did with the theme image before).
 
Sybaris
Topic Author
Posts: 39
Joined: 21 Feb 2019, 10:13

Re: Styling and behaviour of MenuItems

30 Mar 2021, 12:21

Thanks for the detailed response!
I'll see how I can modify my setup to your recommendations.
Noesis 3 is not free, right?
 
User avatar
sfernandez
Site Admin
Posts: 2984
Joined: 22 Dec 2011, 19:20

Re: Styling and behaviour of MenuItems

30 Mar 2021, 12:33

It is free for individual developers or companies with less than 5 employees or external collaborators with a gross annual revenue <100K €.

Who is online

Users browsing this forum: Google [Bot] and 86 guests