在运行时添加控件?(例如textblock) [英] adding controls in runtime?(like textblock)

查看:79
本文介绍了在运行时添加控件?(例如textblock)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好....
我的项目中有一个标签文本框!
我希望我的用户每次单击按钮或输入"时,都会显示一个文本块并包含它的textblock.text内容!
然后我想在另一个页面中,当用户查看产品的详细信息时,显示一些带有标签"em"的文本块....
我想自定义文本的大小以显示带有更多类似标签的标签(例如一个标签已使用5次!必须大于2次标签的标签''的使用!!
数据库已经完成!但是如何在运行时创建文本块呢?!

hello every body....
i have a tag textbox in my project!
i want every time my user clicks on button or "ENTER" a text block show up and contain it''s textblock.text content''s!!
then i want to in another page''s, when user look''s at details of a product, some textblock''s with tag''s on''em show up....
i want to customize the size of the text''s to show the one''s with more similar tag''s( like one tag has been used 5 time''s! must be bigger than a tag with 2 time''s of use!!
data base has been done! but how can i make the textblock''s in runtime?!

推荐答案

无论如何,所有控件总是总是添加.您不会直接看到它,仅仅是因为您在XAML中添加了一些控件(或所有控件),并且实际的添加"代码并未显示为源代码,因为真正的源代码是XAML.但是您不认为它们是我的神秘力量,是吗? :-)

这就是发生的情况:您在XAML中编写布局,然后在构建过程中,首先使用XAML生成实际代码,然后以通常的方式进行编译并由应用程序使用.

那么,现在您想用自己的双手来做一些这样的代码吗?是的,在很多情况下您确实需要它.而且XAML很难使用,或者没有提供足够的表达能力. XAML中有很多无法表达的代码.

因此,这是我的非常笼统的建议,将涵盖许多类似的问题.首先,尝试在一些临时原型应用程序中的XAML简化示例中完成所需的工作.建立它.查找自动生成的C#文件-如果将在项目文件位置下的目录结构中找到它们.加载文件,并查看C#的工作方式.学习它,然后在您的工作中使用.

简单而笼统,不是吗?这种方法从未失败. :-)

祝你好运,
—SA
All controls are always added during run time, anyway. You don''t see it directly only because you add some controls (or all of them) in XAML, and the actual "adding" code is not shown to you as the source code, because the real source is XAML. But you don''t think they are added my some mystical "force", do you? :-)

Here is what happens: you author layout in XAML, and, during the build, the actual code is first generated using the XAML, compiled in a usual way and used by application.

So, now you want to do some of such code with your own hands? Right, there are many cases when you really need it; and XAML is just awkward to use or does not provide enough expressing capabilities. There is a lot of code which cannot be expressed in XAML.

So, here is my, very general advice which will cover many similar questions. First, try to do what you need in a simplified sample, in XAML, in some temporary prototype application. Build it. Find auto-generated C# files — if will find them in directory structure under the location of the project file. Load the files and see how things work in C#. Learn it and then use in your work.

Simple and general, isn''t it? This approach never failed. :-)

Good luck,
—SA


这篇关于在运行时添加控件?(例如textblock)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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