Page 1 of 1

menuitem header set text help newb

Posted: 08 Apr 2015, 19:46
by tseiler
I'm a newb when it comes to xaml and wpf stuff, so any help would great.

I have a menu with a submenu and I have some items dynamically added to the submenu, manually. Not via any sort of data binding stuff.

But what I wanted to do was change the header of the menu when I selected a menu item, so that it changes to the menu item text, to show what was selected with the menu closed.

Basically, I think I want to change the header text, but I can't figure out how to do this.

It looked like maybe I need these guys to mess with the header...
#include <NsGui/HeaderedContentControl.h>
#include <NsGui/HeaderedItemsControl.h>

I have tried messing with "HeaderedContentControl" and "HeaderedItemControl" and I can't tell what the difference is. If I create a "HeaderedContentControl", I can set some text in it (using header->SetHeader("string_goes_here")), but I can't figure out how to fetch the string from it. I tried casting it, but nothing...

HeaderedItemControl doesn't seem to have this functionality to even set the string. But I think I need to use HeaderedItemControl... I think..

I tried messing with GetValue() and GetContent() but I'm not really sure what I'm doing. Any direction would be great.

Thanks,
-Todd

Re: menuitem header set text help newb

Posted: 08 Apr 2015, 22:42
by sfernandez
You can modify the header of any MenuItem by calling SetHeader() function:
void App::OnMenuItemClicked(BaseComponent* sender, const RoutedEventArgs& e)
{
  MenuItem* item = NsDynamicCast<MenuItem*>(sender);
  if (item != 0)
  {
    MenuItem* parentItem = NsDynamicCast<MenuItem*>(item->GetParent());
    if (parentItem != 0)
    {
      NsString itemHeader = Boxing::Unbox<NsString>(item->GetHeader());
      parentItem->SetHeader(itemHeader.c_str());
    }
  }
}
Is this what you are looking for?

Re: menuitem header set text help newb

Posted: 09 Apr 2015, 00:28
by tseiler
Yes, thank you. The thing I was missing was unboxing.