How to show or hide button in a datagrid header?

Tag: silverlight-4.0 , header , accordion , code-behind , show-hide Author: xx646437646 Date: 2011-04-26

I am developing the silverlight application. I am new to the silverlight 4. I am using the following link for reference in my accordion control

In the above link with AccordionItem.Header I am able to show or hide the button control but I am not able to handle the click event on the button control in code behind. So I have used the AccordionItem.HeaderTemplate in my code. I have 4 buttons in my header control. I am able to show and hide the button by using the above link. With HeaderTemplate I am able to handle the click event on the button control in code behind. With HeaderTemplate I am not able to access the button control placed inside HeaderTemplate in code behind. I am getting the NullReferenceException error "The Object reference not set to an instance of the object" How to resolve the above issue ? Can you please provide me any code or link through which I can access the control placed inside the HeaderTemplate in code behind ? If I am doing anything wrong then please guide me.

Best Answer

You can enable the button in the header of datagrid with the following statement in code behind

accordiocntl.SelectionMode = AccordionSelectionMode.ZeroOrOne;

You can refer the link for more details