WPF后台自动添加控件Demo
xaml
<Window x:Class="EBPlugIn2.EBPlugIn2_YJW_13"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:EBPlugIn2"
mc:Ignorable="d" Title=""
Height="300" Width="500">
<Grid x:Name="mainGrid">
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition Height="30"/>
</Grid.RowDefinitions>
<Button Grid.Row="1" x:Name="okBtn" Content="确定" Width="60" Click="okBtn_Click"/>
</Grid>
</Window>
cs
using EBCore;
using GuiDB;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace EBPlugIn2
{
/// <summary>
/// EBPlugIn2_YJW_13.xaml 的交互逻辑
/// </summary>
public partial class EBPlugIn2_YJW_13 : Window
{
public EBPlugIn2_YJW_13()
{
InitializeComponent();
createRadioBtns();
}
private void createRadioBtns()
{
EBD EbD = EBD.Instan;
List<View> views = EbD.ommView;
List<string> viewNames = (from v in views
select v.ViewName).ToList();
//动态创建单选框
StackPanel stackPanel = new StackPanel();
for(int i = 0; i < viewNames.Count; i++)
{
RadioButton radioBtn = new RadioButton();
radioBtn.Content = viewNames[i];
radioBtn.GroupName = "viewRadios";
radioBtn.Checked += RadioBtn_Checked;
stackPanel.Children.Add(radioBtn);
}
ScrollViewer scroller = new ScrollViewer();
scroller.VerticalScrollBarVisibility = ScrollBarVisibility.Auto;
scroller.Content = stackPanel;
Grid.SetRow(scroller, 0);
mainGrid.Children.Add(scroller);
}
private void RadioBtn_Checked(object sender, RoutedEventArgs e)
{
}
private void okBtn_Click(object sender, RoutedEventArgs e)
{
}
}
}
#####
愿你一寸一寸地攻城略地,一点一点地焕然一新
#####
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
2020-07-10 简述python中的深浅拷贝