Igra
Topic Author
Posts: 3
Joined: 09 Feb 2017, 13:17

Main menu item header text not visible

09 Feb 2017, 13:28

Hi,

I have problem with displaying header text in main menu item.

Here is part of xaml:

<StackPanel DockPanel.Dock="Top">
<Menu x:Name="MainMenu" FontFamily="Fonts/#osaka_unicode">
<MenuItem Header="{Converter={StaticResource Translater}, ConverterParameter=IdMainMenuFile }">

Converter gets the IdMainMenuFile parameter and translate it into string "File". But main menu item header is empty.

Strange is that when I use the same code for submenu items, the text is displayed.

Could you please give me some advice how to fix this issue?
 
User avatar
sfernandez
Site Admin
Posts: 3238
Joined: 22 Dec 2011, 19:20

Re: Main menu item header text not visible

09 Feb 2017, 14:12

Hi,

Is it possible that you are missing part of the markup expression? Shouldn't it be something like:
<StackPanel DockPanel.Dock="Top">
  <Menu x:Name="MainMenu" FontFamily="Fonts/#osaka_unicode">
    <MenuItem Header="{Binding SomeProperty,
        Converter={StaticResource Translater}, ConverterParameter=IdMainMenuFile}">
...
One question, which version of NoesisGUI are you using? C++, C# or Unity?

Regards.
 
Igra
Topic Author
Posts: 3
Joined: 09 Feb 2017, 13:17

Re: Main menu item header text not visible

09 Feb 2017, 14:33

I am using NoesisGUI v1.2.6f5

I think, that it is not necessary to bind to SomeProperty.
Same xaml works in C# project (using System.Windows and PresentationFramework.dll) correctly.

But I'll try this.

Thanks
 
KeldorKatarn
Posts: 243
Joined: 30 May 2014, 10:26

Re: Main menu item header text not visible

12 Feb 2017, 19:32

From what I know {Binding SomeProperty} is just a shortcut for Binding Path=SomeProperty, so maybe just {Binding Converter=... would work in case the Binding is necessary?
I've seen this stuff before.

Just a suggestion however. Instead of using a converter, can't you do a custom Markup extension for this globalization stuff? Then again... Noesis probably doesn't support those yet. but once they do I'd go for that instead of a converter.
 
User avatar
sfernandez
Site Admin
Posts: 3238
Joined: 22 Dec 2011, 19:20

Re: Main menu item header text not visible

15 Feb 2017, 19:46

Writing {Binding} will use DataContext as source for the binding. It is the same as {Binding DataContext} or {Binding Path=DataContext}.
The Converter and ConverterParameter are just other properties of the Binding markup extension, as it is Path in the last example.
That's why I think that the original Header="{Converter={StaticResource Translater}, ConverterParameter=IdMainMenuFile }" was missing the Binding class.
 
Igra
Topic Author
Posts: 3
Joined: 09 Feb 2017, 13:17

Re: Main menu item header text not visible

03 Mar 2017, 14:02

Even if I create property like this:
private string idMainMenuFile = "File";

public string IdMainMenuFile
{
	get { return idMainMenuFile; }
	set
	{
		idMainMenuFile = value;
                if (PropertyChanged != null)
                {
                	PropertyChanged(this, new PropertyChangedEventArgs("IdMainMenuFile"));
                }
        }
   }
   
and bind the Menu item Header to this property (like in followin example), I cannot see text "File".
<DockPanel >
	<StackPanel DockPanel.Dock="Top">
		<Menu x:Name="MainMenu"  FontFamily="Fonts/#osaka_unicode">
			<MenuItem Header="{Binding Path=IdMainMenuFile}"/>
		</Menu>
	</StackPanel>
</DockPanel >
Can I find some example with Menu somewhere?

Thanks
 
User avatar
sfernandez
Site Admin
Posts: 3238
Joined: 22 Dec 2011, 19:20

Re: Main menu item header text not visible

09 Mar 2017, 12:11

Hi,

Make sure that DataContext is the expected one for the MenuItem.

I just made a simple test and the binding worked fine:
<Grid
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <DockPanel >
    	<StackPanel DockPanel.Dock="Top">
    		<Menu x:Name="MainMenu" FontFamily="Fonts/#osaka_unicode">
    			<MenuItem Header="{Binding Path=IdMainMenuFile}"/>
    		</Menu>
    	</StackPanel>
    </DockPanel >
</Grid>
using System.ComponentModel;
using UnityEngine;

public class Context: INotifyPropertyChanged
{
    private string idMainMenuFile = "File";

    public string IdMainMenuFile
    {
        get { return idMainMenuFile; }
        set
        {
            idMainMenuFile = value;
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs("IdMainMenuFile"));
            }
        }
    }

    public event PropertyChangedEventHandler PropertyChanged;
}

public class TestBehavior : MonoBehaviour
{
    void Start ()
    {
        var gui = GetComponent<NoesisGUIPanel>();
        var content = gui.GetContent();
        content.DataContext = new Context();
    }
}
But what you probably should use is a hierarchical data template to fill all the menu entries properly:
<Grid
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <DockPanel >
    	<StackPanel DockPanel.Dock="Top">
    		<Menu x:Name="MainMenu" FontFamily="Fonts/#osaka_unicode" ItemsSource="{Binding}">
    		    <Menu.ItemTemplate>
    		        <HierarchicalDataTemplate ItemsSource="{Binding Children}">
    		            <TextBlock Text="{Binding Header}"/>
    		        </HierarchicalDataTemplate>
    		    </Menu.ItemTemplate>
    		</Menu>
    	</StackPanel>
    </DockPanel >
</Grid>
public class MenuEntry
{
    public MenuEntry(string header) { Header = header; Children = new List<MenuEntry>(); }
    public string Header { get; private set; }
    public List<MenuEntry> Children { get; private set; }
}

public class TestBehavior : MonoBehaviour
{
    void Start ()
    {
        var gui = GetComponent<NoesisGUIPanel>();
        var content = gui.GetContent();

        List<MenuEntry> menu = new List<MenuEntry>();
        menu.Add(new MenuEntry("File"));
        menu[0].Children.Add(new MenuEntry("Open"));
        menu[0].Children.Add(new MenuEntry("Save"));
        menu[0].Children.Add(new MenuEntry("Exit"));
        menu.Add(new MenuEntry("Edit"));
        menu[1].Children.Add(new MenuEntry("Copy"));
        menu[1].Children.Add(new MenuEntry("Cut"));
        menu[1].Children.Add(new MenuEntry("Paste"));
        menu.Add(new MenuEntry("Help"));
        menu[2].Children.Add(new MenuEntry("View Help"));
        menu[2].Children.Add(new MenuEntry("About"));

        content.DataContext = menu;
    }
}
I hope this can help.

Who is online

Users browsing this forum: Ahrefs [Bot], Semrush [Bot] and 43 guests