求助:想用c#输出checkbox到界面上
C# 有string[],想把每个string输出成一个checkbox在界面上, 怎么实现啊
要在xaml里面用哪个panel呢?还是什么别的布局?
谢谢!!! 找了一晚上例子了,还是没成。。
using System.Windows; using System.Windows.Controls; namespace WpfApplication1 { public partial class MainWindow { public MainWindow() { InitializeComponent(); var strArray = new[] { "A", "B", "C" }; //加进StackPanel里 foreach (var str in strArray) { var cb = new CheckBox { Content = str, Margin = new Thickness(5, 2, 5, 2) }; Sp.Children.Add(cb); } //加进Button里 var sp = new StackPanel(); foreach (var str in strArray) { var cb = new CheckBox { Content = str, Margin = new Thickness(5, 2, 5, 2) }; sp.Children.Add(cb); } But.Content = sp; //加进ComboBox里 foreach (var str in strArray) { var cb = new CheckBox { Content = str, Margin = new Thickness(5, 2, 5, 2) }; Cob.Items.Add(cb); } } } }