具有 Observable 集合的 XAML 列表框中的动态内容
这是一个很难解释的问题,但我希望它有一个相当简单的解决方案。
我正在 XAML 中编写一个 ListBox 控件,并且网格中列出的 ListBox.ItemTemplate 的大部分布局在整个列表中都是相同的。然而,ListBox 是一个“问题解决程序”,它会挑选出客户订单列表中的异常情况,并要求用户做出一些决定或更改数据,然后才允许其进入邮资系统,邮资系统将向我们收取发送客户订单的费用。
问题类型在具有三种设置的枚举中进行描述,对于三个问题状态中的两个,我需要问题的文本描述(每种问题类型的不同描述以及文本中包含的动态数据)和一个按钮,用于最后一个问题类型我需要文本描述和单选按钮列表。
有没有什么方法可以在 XAML 中包含某种 switch 语句,该语句将决定将哪些内容放入网格单元中,其中内容需要通过告诉问题顺序的枚举值来改变?
This is a bit of a difficult problem to explain, but I'm hoping it has a reasonably simple resolution.
I am writing a ListBox control in XAML and most of the layout for the ListBox.ItemTemplate laid out in a grid is the same throughout the list. However the ListBox is a "Problem Resolver" that picks out anomalies in a list of customer orders and asks the user to make some decision, or change to the data, before allowing it into the postage system which will bill us for dispatching a customer's order.
The problem types are described in an enum with three settings, for two out of the three problem statuses I need a text description of the problem (different description for each type of problem and with dynamic data included in the text) and a button, for the last problem type I need a text description and a radiobutton list.
Is there any way to include a sort of switch statement in the XAML which will decide which content to put in the grid cell where the content needs to vary by just telling it what the Enum value is for the problem order?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这可以通过 DataTemplateSelector 来实现
That could be achieved by DataTemplateSelector
尝试使用 Josh 编写的 Switch Converter,应该适合您:
SwitchConverter – A "switch statements" for XAML - http://josheinstein.com/blog/index.php/2010/06/switchconverter-a-switch-statement-for-xaml/
编辑:
这是 SwitchConverter 的代码,因为 [Josh 的][1] 网站似乎已关闭 -
Try to use the Switch Converter written by Josh, should work for you:
SwitchConverter – A "switch statement" for XAML - http://josheinstein.com/blog/index.php/2010/06/switchconverter-a-switch-statement-for-xaml/
EDIT:
Here is code of SwitchConverter as [Josh's][1] site seems to be down -