Xaml中带有枚举的数据绑定组合框 [英] Databinding combobox with enums in Xaml

查看:117
本文介绍了Xaml中带有枚举的数据绑定组合框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好

我在将数据绑定到xaml的combobox时遇到一些困难.我做了一个非常简单的示例.

好的,到这里了.

我有以下枚举:

Hi all

I have some difficulties binding data into combobox in xaml. I made very simple example to work with.

Ok, here it goes.

I have following enum:

public enum ShirtSize
        {
            Small,
            Medium,
            Large
        }


而且我知道我可以像下面这样填充我的组合框"comboBoxShirtSizes":


And I know that I can fill my combobox "comboBoxShirtSizes" incode like follows:

foreach (ShirtSize e in Enum.GetValues(typeof(ShirtSize)))
      comboBoxShirtSizes.Items.Add(e);

  //Or

  comboBoxShirtSizes.ItemsSource = Enum.GetValues(typeof(ShirtSize));


问题是仅使用Xaml代码如何执行同样的操作:doh :?

最好的问候


The Question is how to do same just using Xaml code :doh: ?

bests regards

推荐答案



使用XAML查看绑定.您可以设置某些控件的数据源,这些控件一旦绑定到后面代码中的集合,便会显示该内容.如果使用依赖项属性,则可以更新这些集合,从而可以更新图形显示.

希望对您有所帮助.

劳伦斯
Hi,

Look into bindings using XAML. You are able to set the data source of certain controls which, once bound to collections in your code behind will display that content. If you use dependency properties you''re able to update these collections which in tern updates your graphical display.

I hope this helps.

Laurence


毕竟是错字.在xaml中使用ObjectdataProvider解决了我的问题.还需要将我的课程添加到xaml中的引用中...:)
It was typo afterall. Using ObjectdataProvider in xaml solved my problem. Also needed add my class in reference in xaml... :)


这篇关于Xaml中带有枚举的数据绑定组合框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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