绑定到与指定内容的组合框 [英] Binding to a combobox with specified content

查看:197
本文介绍了绑定到与指定内容的组合框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道我怎么能绑定到组合框项目时,它的内容被指定。我能保存内容到数据库,但是当我试图重新进入备案,组合框将不会改变的的SelectedItem

I'm wondering how can I bind to a ComboBox item when it's content is specified. I'm able to save the content to the database but when I try to re-enter the record, the ComboBox won't change at all to the SelectedItem.

<ComboBox SelectedItem="{Binding Duration, UpdateSourceTrigger=PropertyChanged}" SelectedIndex="0" Style="{StaticResource CombBox}" MinWidth="60">
    <ComboBoxItem Content="15 Minutes"/>
    <ComboBoxItem Content="30 Minutes"/>
    <ComboBoxItem Content="45 Minutes"/>
    <ComboBoxItem Content="1 Hour"/>
</ComboBox>

public string Duration { get { return Entity.Duration; } set { Entity.Duration = value; NotifyOfPropertyChange(); } }



我这不是我的设置绑定正确吗?

Am I not setting my bindings correct?

推荐答案

第一:在您XAML中使用这个命名空间的xmlns:SYS = CLR的命名空间:系统;装配= mscorlib程序

First: In you xaml use this namespace xmlns:sys="clr-namespace:System;assembly=mscorlib"

二:更改组合框这样:

<ComboBox SelectedItem="{Binding Duration, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}">
    <sys:String>15 Minutes</sys:String>
    <sys:String>30 Minutes</sys:String>
    <sys:String>45 Minutes</sys:String>
</ComboBox>



第三:你是怎么实现的 INotifyPropertyChanged的?看来你不作为字符串的通知机制发送的属性名称。它应该是这样的(insted的的 NotifyOfPropertyChange()

Third: How did you implement the INotifyPropertyChanged? It seems you don't send the properties name as string to the Notify mechanism. It should be something like this (insted of NotifyOfPropertyChange())

PropertyChanged(this, new PropertyChangedEventArgs("Duration"));

这篇关于绑定到与指定内容的组合框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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