如何从Listview中获取字符串的值

时间:2016-11-24 13:01:52

标签: c# wpf

我有一个名为lvNotities的列表视图,其中包含Notes类中的一些值。 listview中的值来自列表:public ObservableCollection Mappen = new ObservableCollection();

public class Notes
{
    public ObservableCollection<Notes> Mappen = new ObservableCollection<Notes>();
    private string titel;
    public string Titel
    {
        get { return this.titel; }
        set
        {
            if (this.titel != value)
            {
                this.titel = value;
                this.NotifyPropertyChanged("Titel");
            }
        }
    }

    public event PropertyChangedEventHandler PropertyChanged;

    public void NotifyPropertyChanged(string propName)
    {
        if (this.PropertyChanged != null)
            this.PropertyChanged(this, new PropertyChangedEventArgs(propName));
    }
}

例如:

  • 两个

点击代码:

StreamWriter outputStream = File.CreateText(Convert.ToString(lvNotities.SelectedItem) + ".txt");

因此,当我双击该项目时,我希望使用名称制作文档,例如:One.txtTwo.txt

但是当我这样做时,文档保存为:WpfApplication.Notes

我知道解释很糟糕,但希望有人知道我想要什么。

2 个答案:

答案 0 :(得分:0)

试试这个......

StreamWriter outputStream = File.CreateText(Convert.ToString(((System.Windows.Controls.ContentControl)lvNotities.SelectedItem).Content) + ".txt");

答案 1 :(得分:0)

这有用吗?

StreamWriter outputStream = File.CreateText(((Notes)lvNotities.SelectedItem).Titel + ".txt");
相关问题