Click here to Skip to main content
15,881,967 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I am creating context menu programatically in c# wpf, My context menu items are installed driver in my system. and contextmenu icon are radio button, when I am clicking on contextmenu headre I can able to enable corresponding radio button, like
C#
RadioButton rb = menuItem.Icon as RadioButton;

           if (rb != null)
           {
               rb.IsChecked = true;}

its working fine, but If I checked radio button i want corresponding contextmenu header name how can I do this.?

What I have tried:

I tried to
C#
 radBtn.Checked += radBtn_Checked;
void radBtn_Checked(object sender, RoutedEventArgs e)
        {
            ?????
        }

how to get this.
Thanks in advance.
Posted
Updated 7-Nov-17 0:43am

1 solution

here is my solution.
C#
RadioButton rb = (RadioButton)e.Source;
DependencyObject o = rb;
MenuItem item = null;
do
{
   o = VisualTreeHelper.GetParent( o );
   if( o == null ) break;
   item = o as MenuItem;
} while( item == null );
string header = item?.Header as string;
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900