Main menu item header text not visible
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?
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?
-
-
sfernandez
Site Admin
- Posts: 3238
- Joined:
Re: Main menu item header text not visible
Hi,
Is it possible that you are missing part of the markup expression? Shouldn't it be something like:
One question, which version of NoesisGUI are you using? C++, C# or Unity?
Regards.
Is it possible that you are missing part of the markup expression? Shouldn't it be something like:
Code: Select all
<StackPanel DockPanel.Dock="Top">
<Menu x:Name="MainMenu" FontFamily="Fonts/#osaka_unicode">
<MenuItem Header="{Binding SomeProperty,
Converter={StaticResource Translater}, ConverterParameter=IdMainMenuFile}">
...
Regards.
Re: Main menu item header text not visible
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
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:
Re: Main menu item header text not visible
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.
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.
-
-
sfernandez
Site Admin
- Posts: 3238
- Joined:
Re: Main menu item header text not visible
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.
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.
Re: Main menu item header text not visible
Even if I create property like this:
and bind the Menu item Header to this property (like in followin example), I cannot see text "File".
Can I find some example with Menu somewhere?
Thanks
Code: Select all
private string idMainMenuFile = "File";
public string IdMainMenuFile
{
get { return idMainMenuFile; }
set
{
idMainMenuFile = value;
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs("IdMainMenuFile"));
}
}
}
Code: Select all
<DockPanel >
<StackPanel DockPanel.Dock="Top">
<Menu x:Name="MainMenu" FontFamily="Fonts/#osaka_unicode">
<MenuItem Header="{Binding Path=IdMainMenuFile}"/>
</Menu>
</StackPanel>
</DockPanel >
Thanks
-
-
sfernandez
Site Admin
- Posts: 3238
- Joined:
Re: Main menu item header text not visible
Hi,
Make sure that DataContext is the expected one for the MenuItem.
I just made a simple test and the binding worked fine:
But what you probably should use is a hierarchical data template to fill all the menu entries properly:
I hope this can help.
Make sure that DataContext is the expected one for the MenuItem.
I just made a simple test and the binding worked fine:
Code: Select all
<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>
Code: Select all
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();
}
}
Code: Select all
<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>
Code: Select all
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;
}
}
Who is online
Users browsing this forum: Ahrefs [Bot], Semrush [Bot] and 43 guests