问题动态创建组合框 [英] Issue in creating combobox dynamically

查看:112
本文介绍了问题动态创建组合框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图动态创建一个组合框,但无法创建它。
下面是我写的代码



 组合框com_dynamic =新的ComboBox()。 
com_dynamic.Height = 50;
com_dynamic.Width = 100;
LayoutRoot.Children.Add(com_dynamic);
tb.Margin =新厚度(0,145,87,0);
tb.VerticalAlignment = VerticalAlignment.Top;
tb.Horizo​​ntalAlignment = Horizo​​ntalAlignment.Right;

ComboBoxItem com_dynamic_item =新ComboBoxItem();
com_dynamic.AddChild(com_dynamic_item);
com_dynamic_item.Content =ITEM1;


解决方案

您也应该组合框添加到一个容器控件。如果你想将其添加在 LayoutRoot ,那么这就是你缺少的行。

  LayoutRoot.Children.Add(com_dynamic); 

您可以使用它的利润率在容器中重新定位组合框。


I tried to create a ComboBox dynamically, but cannot create it. Here is the code that I wrote.

        ComboBox com_dynamic = new ComboBox();            
        com_dynamic.Height = 50;
        com_dynamic.Width = 100;           
        LayoutRoot.Children.Add(com_dynamic);           
        tb.Margin = new Thickness(0, 145, 87, 0);
        tb.VerticalAlignment = VerticalAlignment.Top;
        tb.HorizontalAlignment = HorizontalAlignment.Right;

        ComboBoxItem com_dynamic_item = new ComboBoxItem();
        com_dynamic.AddChild(com_dynamic_item);
        com_dynamic_item.Content = "item1";

解决方案

You should also add the combobox to a container control. If you want to add it in the LayoutRoot, then this is the line you are missing.

LayoutRoot.Children.Add(com_dynamic);

You can reposition the combobox using its margin in the container.

这篇关于问题动态创建组合框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆