首页 > 其他分享 >WPF UniformGrid contain children auto resize

WPF UniformGrid contain children auto resize

时间:2024-09-03 17:15:51浏览次数:4  
标签:Media UniformGrid Loaded Windows auto System contain using MainWindow

//xaml
<Window x:Class="WpfApp332.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:WpfApp332"
        mc:Ignorable="d" WindowState="Maximized"
        Title="MainWindow" Height="450" Width="800">
    <UniformGrid x:Name="uniformGrid">
         
    </UniformGrid>
</Window>


//cs
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.Controls.Primitives;
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 WpfApp332
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        Random rnd { get; set; }
        public MainWindow()
        {
            rnd = new Random();
            InitializeComponent();
            this.Loaded += MainWindow_Loaded;
        }

        private void MainWindow_Loaded(object sender, RoutedEventArgs e)
        {
            for(int i=0;i<2000;i++)
            {
                Button btn = new Button();
                btn.Background = new SolidColorBrush(Color.FromRgb((byte)rnd.Next(255), (byte)rnd.Next(255), (byte)rnd.Next(255)));
                if(!uniformGrid.Children.Contains(btn))
                {
                    uniformGrid.Children.Add(btn);
                }
            }
        } 
    }
}

 

 

 

标签:Media,UniformGrid,Loaded,Windows,auto,System,contain,using,MainWindow
From: https://www.cnblogs.com/Fred1987/p/18394984

相关文章

  • 从零开始:用Flask和UIAutomation构建RPA微信自动群发工具
    文章目录前言一、环境搭建系统要求flask安装uiautomation安装二、群发功能的实现要导入的包1.构建WxOperation类2.搜寻被发送人3.发送文本4.发送文件5.接收消息三、构建后端服务要导入的包文件框架1.index.html文件2.app.py四、成果展示总结前言在这个数字化......
  • Project 1: Specification for Automail
    Project1:SpecificationforAutomailBackground:AutomailDeliveringSolutionsInc.(DS)hasrecentlydevelopedandprovidedaRoboticMailDeliverysystemcalledAutomailtothemarket.Automailisanautomatedmailsortinganddeliverysystemdesigned......
  • Autodesk 3DS Max v2025 激活版下载及安装教程
    前言Autodesk3dsMax是一款功能强大的3D建模和动画解决方案,游戏开发人员、视觉效果艺术家和平面设计师使用它来创建庞大的世界、令人惊叹的场景和引人入胜的虚拟现实(VR)体验。Autodesk3DSMAX是业界使用最广泛的3D建模和动画软件程序之一,它将为用户提供一系列新功能和工......
  • Autodesk Maya v2025 激活版下载及安装教程 (三维动画建模渲染)
    前言AutodeskMaya是一款用于三维动画、建模、仿真和渲染的软件。它是电影、电视、游戏和虚拟现实等领域中最流行的专业工具之一,被广泛用于制作复杂的特效和动画。功能完善,工作灵活,制作效率高,真实感强,是一款高端电影制作软件。它集成了最先进的动画和数字特效技术的别名和波前。......
  • RAG在PostgreSQL上的实现:使用Azure Container Apps和OpenAI构建智能问答系统
    RAG在PostgreSQL上的实现:使用AzureContainerApps和OpenAI构建智能问答系统随着人工智能技术的快速发展,越来越多的企业和开发者开始探索如何将AI能力整合到现有的应用系统中。本文将介绍一种基于检索增强生成(RetrievalAugmentedGeneration,RAG)的方案,通过结合AzureCo......
  • 运维系列&AI系列&Lenovo-G双系统系列(前传-装之前搜索的):Scrapy爬虫的打包Auto-py-to-ex
    Scrapy爬虫的打包Auto-py-to-exe/PyinstallScrapy爬虫的打包Auto-py-to-exe/Pyinstall前言步骤Scrapy代码部分1.系统调用方案2.API启动方案auto-py-to-exe部分1.安装2.配置1.将基础的目录配置进去,包括`spiders`的上级目录,和对应的库文件2.把对应的python环境库文......
  • 将autodl服务器连接到Pycharm上使用
    第一步下载专业版pycharm(可以找那种破解版)第二步autodl算力市场选择合适的显卡、计费方式、框架、充值、找个空闲的开机第三步打开专业版pycharm,主菜单-设置-python解释器-添加解释器-ssh 第四步回到autodl复制登陆指令,填写到主机位置,五位数字就是端口,root就是用户名......
  • 【编程规范具体案例(基于Qt、微软、谷歌和AUTOSAR C++14 参考)】 C++ 编码规范 之程序设
    目录标题基本元素3.1类和结构体3.1.1\[必须]使用恰当的访问修饰符来管理类成员的可见性3.1.2\[必须]在类中合理使用默认的特殊成员函数3.1.3\[必须]提供清晰且尽可能一致的类接口3.1.4\[建议]优先使用初始化列表来初始化类成员3.1.5\[建议]使用抽......
  • 第3章_auto占位符(C++11~C++17)
    第3章auto占位符(C++11~C++17)3.1重新定义的auto关键字在C++11中静态成员变量是可以用auto声明并且初始化的,不过前提是auto必须使用const限定符。staticconstautox=5;遗憾的是,const限定符会导致x常量化,显然这不是我们想要的结果。在C++17标准中,对于静态成员变量,auto可以......
  • Day27-containerd
    containerd的历史(1)早在2016年3月,Docker1.11的DockerEngine里就包含了containerd,而现在则是把containerd从DockerEngine里彻底剥离出来,作为一个独立的开源项目独立发展,目标是提供一个更加开放、稳定的容器运行基础设施。和原先包含在DockerEngine里containerd相比,独立的conta......