繁体   English   中英

将SelectedItem子类列表绑定到文本框

[英]Binding SelectedItem subclass list to a textbox

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

标签是子类

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

如果我这样做

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

它只显示为空

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

编辑所以我有一个包含标签列表的课本。 Name是Tags的属性。

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"); }
        }
}

我解决了它,答案是在转换器而不是使用string.Join我正在使用String Builders Append,现在它正确绑定。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM