Dynamically add radiobuttons in submenu in C# WPF -
I would like to implement a dynamic menu in my application, which is written in C # and using WPF .
MenuSubSerialPortSelect.Items.Clear (); Fresh (string element in GlobalWars. ActualSialial ports) {menu item = new menu item (); Item.Header = element; MenuSubSerialPortSelect.Items.Add (item); }
Adding a sub menu is functional, but how can I add some radio buttons to this style?
I have read some websites that describe that another "template" can be used there, but I can not find a matching solution for me.
attribute item.IsCheckable = true;
I do not have a solution -
try it
< Code> & lt; Window x: class = "stackworflow.main window" xmlns = "http://schemas.microsoft.com/winfx/ 2006/xaml/presentation" xmlns: x = "http://schemas.microsoft.com/winfx/ 2006 / xaml "xmlns: local =" clr-namespace: stack overflow "title =" main window "height =" 350 "width =" 525 "& gt; & Lt; Window.Resources & gt; & Lt; Radio button x: key = "radio button" horizontal alignment = "center" groupname = "mygroup" ishtativisible = "wrong" /> & Lt; Style TargetType = "MenuItem" & gt; & Lt; Setter property = "symbol" value = "{static resource radio button}" /> & Lt; EventSetter Event = "Click" Handler = "MenuEtym_click" /> & Lt; / Style & gt; & Lt; /Window.Resources> & Lt; Grid Background = "Red" & gt; & Lt; Grid.ContextMenu> & Lt; ContextMenu & gt; & Lt; MenuItem Header = "Print" / & gt; & Lt; MenuItem header = "save" /> & Lt; MenuItem Header = "Open" /> & Lt; MenuItem Header = "Delete" /> & Lt; MenuItem Header = "Update" /> & Lt; / ContextMenu & gt; & Lt; /Grid.ContextMenu> & Lt; / Grid & gt;
Public partial class main window: window {public key window ()} {InitializeComponent (); Datacontax = new view modal (); } Private Zero MenuItem_Click (Object Sender, System.Windows.RoutedEventArgs e) {MenuItem menuItem = Sender as MenuItem; If (menuItem! = Null) {RadioButton RB = menuItem.Icon to RadioButton; If (rb! = Null) {rb.IsChecked = true; }}}}
I have only the presence of stable men here.
Comments
Post a Comment