在xaml中具有类似控件的TabControls和TabItems [英] TabControls and TabItems having similar controls in xaml

查看:68
本文介绍了在xaml中具有类似控件的TabControls和TabItems的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在特定任务中,我具有TabControl,并且定义的Tab项如下所示
< TabControl>标头="Tabs1" TabStripPlacement =顶部" ...
<标签项目>名称="MyTab1"颜色=红色"/>
<标签名称="abc" ...........>
< TextBox名称="xyz">
</TabItem>
<标签项目>名称="MyTab2" Color =蓝色"/>
<标签名称="abc" ...........>
< TextBox名称="xyz">
</TabItem>
</TabControl>
这里的TabControl包含TabItems,即MyTab1和MyTab2,但是控件,即Name和TextBox相似,如果在Xaml中,我如上所述复制上述实体,则会报错(已经定义了控件),如何我保证MyTab1& MyTab2在a.xaml和a.xaml.cs中具有相同的控件有效吗?

< b>详细说明:让我们假设清除/更多清除"作为标签名称,其中超级清除标签是超级设置的(包含所有控件
(清除标签)),并添加一些它自己的标签,但是我们需要在单个a.Xaml和a.xaml.cs中保留Clear/MoreClear Tab的通用名称而不会发生名称冲突,仅基于两种选择之一才能显示内容向用户显示清除标签"和更多清除标签",请说明我们该怎么做?</b>
在此先感谢...

谨致问候.

Samanth_99

In the specific task, I have TabControl and Tab Item defined has below
<TabControl> Header = "Tabs1" TabStripPlacement="Top"...
<Tab Item> Name= "MyTab1" Color="Red" />
<Label Name = "abc" ...........>
<TextBox Name = "xyz" >
</TabItem>
<Tab Item> Name= "MyTab2" Color="Blue" />
<Label Name = "abc" ...........>
<TextBox Name = "xyz" >
</TabItem>
</TabControl>
Here the TabControl contains TabItems ie., MyTab1 and MyTab2, but the controls viz., Name and TextBox are similar, If in my Xaml, I replicate the above entities as above, I get error(Already the controls are defined), How can I ensure, that MyTab1 & MyTab2 having same controls in a.xaml and a.xaml.cs works?

<b>To Elaborate : Let us Assume Clear/ More Clear as tab name where More Clear Tab is super set (contains all controls
of Clear Tab) and add few of its, own, but we need to retain the common names for Clear/MoreClear Tab without name collisions, in single a.Xaml and a.xaml.cs, only based on Either selections should display the contents of Clear Tab and More Clear Tab to the user, Please clarify how we could do the same?</b>
Thanks in Advance...

With Regards.

Samanth_99

推荐答案

您无需担心.开始定义控件和选项卡页,添加内部结构,但可能没有名称.使用Intellisense;它不会让你犯错.运行它以确保其正常工作并看起来正确.然后需要通过代码访问哪些元素并根据需要添加名称-唯一名称,唯一性的范围就是整个Window类. (您的代码的问题是名称缺乏这种唯一性.名称会成为自动生成的类成员,以防万一您还没有获得名称:-).)

顺便说一句,标签根本不需要名称,除非您想在代码中动态更改其颜色,文本等,我不建议这样做.

相反,它们需要与标签元素绑定,因为标签的主要目的是为标签元素提供键盘快捷键(通过带下划线的热键字符).例如:
There is nothing you have to care about. Start to define control and the tab pages, add inner structure, but perhaps without names. Use Intellisense; it won''t let you to do a mistake. Run it to make sure it works and look properly. Then thing which elements you need to access via code and add names as you need them — unique names, the scope of uniqueness is your whole Window class. (The problem of your code is the lack of such uniqueness in names. Names become auto-generated class members — in case you did not get it yet :-).)

By the way, labels do not require names at all, unless you want to change their color, text, etc. dynamically in code, which I don''t recommend.

Instead, they need binding with the labelled element, because main purpose of labels is to provide a keyboard shortcut (via underscore-prefixed hot key character) to a labelled element. For example:
<Label Target="{Binding ElementName=xyz}">_Abc;/Label>

,其中根据代码,xyz是标记为TextBox的名称有问题的样本.

请参阅: http://msdn.microsoft.com/en-us/library /system.windows.controls.label.aspx [

where xyz is the name of your labelled TextBox, according the code sample in question.

Please see: http://msdn.microsoft.com/en-us/library/system.windows.controls.label.aspx[^].

—SA


这篇关于在xaml中具有类似控件的TabControls和TabItems的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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