将SelectedItem子类列表绑定到文本框 [英] Binding SelectedItem subclass list to a textbox

查看:97
本文介绍了将SelectedItem子类列表绑定到文本框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在文本框中显示已连接字符串的列表。我使用转换器的功能很棒。问题是当我尝试将所选项子类绑定到文本框时,它不会显示值。它显示Projectname.Model.Tag



标签是子类

I want to display a list of joined strings to a textbox. I use converter for that which works great. The problem is when I try to bind the selected item sub class to a textbox, it doesn't display the values. It displays Projectname.Model.Tag

Tags is the subclass

<TextBox HorizontalAlignment="Left"  Height="23" Text="{Binding Path=SelectedItem.Tags,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged,Converter={StaticResource myConverter}}" VerticalAlignment="Top" Width="auto"/>

我的模型 

My models 

public class Book:INotifyPropertyChanged
    {

        private int _idBook;
        private string _title;
        private ObservableCollection<Tag> _tag;

        public int IdBook
        {
            get { return _idBook; }
            set { _idBook = value; }
        }

        public string Title
        {
            get { return _title; }
            set { _title = value; }
        }
        public ObservableCollection<Tag> Tags
        {
            get { return _tag; }
            set { _tag = value; OnPropertyChanged("Tags"); }
            }
}




 public class Tag:INotifyPropertyChanged
    {

        private int _idTag;
        private string _name;

        public int IdTag
        {
            get { return _idTag; }
            set { _idTag = value; OnPropertyChanged("IdTag"); }
        }

        public string Name
        {
            get { return _name; }
            set { _name = value; OnPropertyChanged("Name"); }
        }
}

如果我这样做,它只显示空白 

If I do this it just displays empty 

<TextBox HorizontalAlignment="Left"  Height="23" Text="{Binding Path=SelectedItem.Tags.Name,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged,Converter={StaticResource myConverter}}" VerticalAlignment="Top" Width="auto"/>

如何将所选项目正确绑定到文本框?

How do I properly bind the selected item to a textbox?

推荐答案



标签是一个集合。您要绑定此集合的哪个项目?绑定到属性"SelectedItem"。属性"SelectedItem"在哪里?

Hi,
tags is a collection. Which item of this collection you want to bind? You bind to property "SelectedItem". Where is the property "SelectedItem"?


这篇关于将SelectedItem子类列表绑定到文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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