本文介绍了[UWP] [C#] XAML UWP:如何用自定义属性创建一堆按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我有一个< VariableSizedWrapGrid Name =" someName"取向= QUOT;垂直"等等...>< / VariableSizedWrapGrid> 现在我需要创建一堆按钮 - 类似这样: ... for(int i = 0; i< 15; i ++){ CreateButton(i); } .... private void CreateButton(int inId){ Button button = new Button(); button.Name =" CreatedButton" + inId; button.MYPROPERTY = inId; //不知道如何做这个 button.Click =" ProcessCreatedButtonClick" ;; //不确定这一行是否有效 someName.Children.Add(button); } private void ProcessCreatedButtonClick(object sender,RoutedEventArgs e){ id clickedButtonId = ??? //(以某种方式获得MYPROPERTY) .... } 所以我的问题是: 1)如何设置MYPROPERTY? 2)如何正确清除网格(someName)的内容?将 somename.Children.Clear()工作吗? 谢谢:)解决方案 I have a <VariableSizedWrapGrid Name="someName" Orientation="Vertical" etc...></VariableSizedWrapGrid >Now I need to create a bunch of buttons - something like this:...for(int i=0; i<15; i++){ CreateButton(i);}....private void CreateButton(int inId){ Button button = new Button(); button.Name = "CreatedButton"+inId; button.MYPROPERTY = inId; // not sure how to do THIS button.Click = "ProcessCreatedButtonClick"; // not really sure if this line will work someName.Children.Add(button);}private void ProcessCreatedButtonClick(object sender, RoutedEventArgs e){ id clickedButtonId = ??? //(get MYPROPERTY somehow) .... }So my questions are:1) how to set MYPROPERTY?2) how do I clear the content of my grid (someName) properly? Will somename.Children.Clear() work?Thanks :) 解决方案 这篇关于[UWP] [C#] XAML UWP:如何用自定义属性创建一堆按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 09-27 15:31