如何在C#中实现条件WPF? [英] how to implement conditional WPF in C#?

查看:150
本文介绍了如何在C#中实现条件WPF?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨 我在C#WPF中实现此问题:

Hi I have a problem with implementing this in C# WPF:

if(condition1)
   <myusercontrol:usercontroltabpagecontent1 />
else if(condition2)
   <myusercontrol:usercontroltabpagecontent2 />
else  
   <myusercontrol:usercontroltabpagecontent3 />

推荐答案

您无法在xaml中定义if条件.
但是,您可以将转换器用作解决方法-请参见此处 [ ^ ].
You cannot define if conditions in a xaml.
However, you can use a converter as a workaround - see here[^].


如果是我,我会在xaml中创建标签页,但最初将它们设置为隐藏(或折叠).然后,在后面的代码中(或通过选项卡控件的控制模板中的触发器),我将显示/隐藏相应的页面.
If it were me, I would create the tab pages in xaml, but set them initially to be hidden (or collapsed). And then, in the code behind (or via triggers in the control template for the tab control), I would show/hide the pages as appropriate.


除了JSOP所说的,还要检查一下用户可以很好地控制并识别相似的项目/控件.您甚至可以只创建一个用户控件,并在运行时动态更改内容.
In addition to what JSOP said, examine the user controls very well and identify items/control that are similar. You can even create just one user control and dynamically change the content at run-time.


这篇关于如何在C#中实现条件WPF?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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