我如何通过选择组合框项目来更改标签? [英] How do I..change the labels by selecting combobox item?.

查看:62
本文介绍了我如何通过选择组合框项目来更改标签?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有2个标签和1个组合框。所以我想要在选择一个组合框项目时更新标签内容...

如何通过Xaml处理这个问题?

i使用MVVM模式。所以请不要给我CodeBehind解决方案。

I have 2 labels and 1 combobox.so i want the content of labels update when one combobox item selected...
how can i handle this issue by Xaml?
i use MVVM pattern.so please don't give me CodeBehind Solution.

推荐答案

Mahyar .prog写道:
Mahyar.prog wrote:

我使用MVVM模式。所以请不要给我CodeBehind解决方案

I use MVVM pattern.so please don't give me CodeBehind Solution

这是这个荒谬的问题中最荒谬的。



MVVM是架构模式,不多也不少: http://en.wikipedia.org/wiki/MVVM [ ^ ]。



它确实具有特定于WPF和Silverlight的实现,但这一事实并不妨碍使用代码隐藏甚至略微。此外,这不是真正的代码背后,这仍然是代码,与其他与XAML无关的代码没有区别。



请参阅我的评论题。我觉得XAML将许多开发人员从真正的可支持和可读的编程转移到XAML技巧上,这些技巧对于这种特定的技术来说太具体了,并且引发了许多非便携式解决方案。基于Designer的开发已经发生的事情现在发生在XAML:过度使用和滥用。谁告诉XAML的解决方案在任何方面都更优雅或更有益?这是将一些UI与功能的其他方面隔离开来的不错尝试之一,但是在XAML级别过度使用所有这些绑定会导致相反的极端:尝试将所有功能都粘贴到XAML中并真正制作XAML代码棘手,不可读和不可移植。不要落入这个。







对于代码解决方案,请看我的过去回答: combobox.selectedvalue在winform中显示{} [ ^ ]。



对不起,它最初是为 System.Windows.Forms 编写的,但也适用于WPF。这个想法是在组合框的列表项中存储不是字符串,而是信息类型的实例,覆盖 System.Object.ToString()来控制什么是在UI中显示。



-SA

This is the biggest absurd in this already absurd question.

MVVM is the architectural pattern, no more no less: http://en.wikipedia.org/wiki/MVVM[^].

It does have the implementation specific to WPF and Silverlight, but this fact does not discourage the use of "code-behind" even slightly. Moreover, this is not really "code behind", this is still code, no different from other kind of code not related to XAML.

Please see my comment to the question. I feel how much XAML diverts many developers from real well-supportable and readable programming into doing XAML tricks which are too specific to this particular technology and provoke a lot of non-portable solutions. The same thing which already happened to the Designer-based development now happens to XAML: overuse and abuse. Who told that XAML-only solution is more elegant or beneficial in any way? This is one of the decent attempt to isolate some UI from other aspects of functionality, but overusing all those kinds of "binding" at the level of XAML leads to the opposite extreme: attempt to stick all the functionality into XAML and make XAML code really tricky, non-readable and non-portable. Don't fall into this.



For code solution, please see my past answer: combobox.selectedvalue shows {} in winform[^].

Sorry, it was originally written for System.Windows.Forms but also applicable to WPF. The idea is to store not strings in the list items of a combo box, but the instances of the informative type, overriding System.Object.ToString() to control what is to be shown in UI.

—SA


这篇关于我如何通过选择组合框项目来更改标签?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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