We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

TitleBar extra buttons

i have a RibbonWindow with a Ribbon.

On my Window's Loaded exvent I have the following code:

WindowTitleBarButton HelpButton = null;

var titleBar = VisualUtils.FindDescendant(sender as RibbonWindow, typeof (TitleBar)) as TitleBar;

if (titleBar != null)

HelpButton = titleBar.Template.FindName("HelpButton", titleBar) as WindowTitleBarButton;

if (HelpButton != null)

{

HelpButton.Click += HelpButton_Click;

HelpButton.ToolTip = "Help";

}


However, HelpButton is always null - even though the button does show up

6 Replies

LR Luís Rodrigues August 29, 2016 12:44 PM UTC

Ok

Moving that peice of code to my Ribbon's Loaded event rather then RibbonWindow loaded fixed my issue.
Now HelpButton is no longer null

However, Ribbon's Loaded event fires twice which means i end up assigne the Helpbutton's event twice

I'll have to add a check to only run that piece of code on first time Loaded fires


MS Mariappan S Syncfusion Team August 30, 2016 06:05 AM UTC

Hi Luís, 

Thanks for your update 

Query: “Ribbon's Loaded event fires twice which means i end up assigne the Helpbutton's event twice” 

Can you please explain your query clearly and also let us know if you need any other assistance for this? 

Regards, 
Mariappan S. 



LR Luís Rodrigues August 30, 2016 08:09 AM UTC

Let me try to explain it

I'm using the Ribbon Control in my project. The Ribbon Control has a 'Loaded' event. so i created an event handler for the Ribbon's Loaded event and placed the code that assigns an event handler to the HelpButton's Click event in it.

Problem is, Ribbon's Loaded event fires twice - so i ended up assigning the HelpButton's Click event twice.

That means, when i clicked the ? button, It would also run my event handler twice - so if my HelpButton's Click event Handler would open Google,com in a browser, there would be two browser windows/tabs per click.

My solution was to add a signal field so i would know i was on my second Ribbon Loaded event firing.

Something like:

 if (!_set)
 {

WindowTitleBarButton HelpButton = null;

var titleBar = VisualUtils.FindDescendant(sender as RibbonWindow, typeof (TitleBar)) as TitleBar;

if (titleBar != null)

HelpButton = titleBar.Template.FindName("HelpButton", titleBar) as WindowTitleBarButton;

if (HelpButton != null)

{

HelpButton.Click += HelpButton_Click;

HelpButton.ToolTip = "Help";

}

_set = true;

}



MS Mariappan S Syncfusion Team August 31, 2016 10:07 AM UTC

Hi Luís   
   
Thanks for your update.   
   
We have prepared simple Ribbon sample with Loaded event. But we were unable to reproduce the reported issue. In this sample, Ribbon Loaded eventgets fired only once.   
   
Please download the sample from the below link.   
   
Sample link: RibbonSample
 
   
If the issue still persist, could you please provide more information or reproducible sample. It would be very helpful for us to resolve your problem at the earliest.   
   
Regards,   
Mariappan S. 



LR Luís Rodrigues August 31, 2016 05:16 PM UTC

Hi

Kept thinkiring on this since it made no sense to fire twice and i figured it out

The Ribbon's Loaded get's fired again every time i apply a new theme
I'm giving users the option to switch theme on the fly

I now don't need that _set field anymore since i simply removed the event handler before applying the new theme
This makes it so that when Loaded fires again due to the change of theme, it's no problem to add the handler again

So far it seams to have fixed it


MS Mariappan S Syncfusion Team September 1, 2016 04:42 AM UTC

Hi Luís, 

Thanks for your information 

Please let us know if you need further assistance. 

Regards, 
Mariappan S. 


Loader.
Live Chat Icon For mobile
Up arrow icon