Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/328.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# wpf可编辑列表视图_C#_Wpf_Listview - Fatal编程技术网

C# wpf可编辑列表视图

C# wpf可编辑列表视图,c#,wpf,listview,C#,Wpf,Listview,我正在尝试使ListView中的字段可编辑。 我的意思是,当我在listView中选择行时,一个字段变成textbox而不是textblock。 但它不起作用——我一直看到这两个控件 xaml: 以及包含绑定到listview的ObservableCollection的网络类: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Collections

我正在尝试使ListView中的字段可编辑。 我的意思是,当我在listView中选择行时,一个字段变成textbox而不是textblock。 但它不起作用——我一直看到这两个控件

xaml:

以及包含绑定到listview的ObservableCollection的网络类:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Windows;
using System.Xml.Serialization;

namespace fastnn_speedTest
{

  public class Network 
  {
    public class Layer : INotifyPropertyChanged
    {
        public enum ActivFunction { LINEAR, EXPONENTIAL, ARCUSTANGENT }

        private string name;

        [XmlIgnore]
        public string Name
        {
            get
            {
                return name;
            }
            set 
            {
                name = value;
                RaisePropertyChanged("Name"); 
            }
        }

        [XmlAttribute]
        public ActivFunction Activation { get; set; }

        [XmlAttribute]
        public int Neurons { get; set; }

        public event PropertyChangedEventHandler PropertyChanged;

        protected virtual void RaisePropertyChanged(String propertyName)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }

    }

    public ObservableCollection<Layer> Layers { get; set; }

    public Network()
    {
        Layers = new ObservableCollection<Layer>();
    }

    public void AddLayer(Layer layer)
    {
        int last = Layers.Count;
        if (last > 0)
        {

            Layers.Last().Name = "Layer " + last + " (hidden)";
        }
        layer.Name = "Layer " + (last + 1) + " (output)";
        Layers.Add(layer);
    }

    public void RemoveLayer(int index)
    {
        if( index >= 0 && index < Layers.Count )
            Layers.RemoveAt(index);
    }

    public void Clear()
    {
        Layers.Clear();
    }

    public void Validate()
    {
        if (Layers.Count < 1)
            throw new ArgumentException("minimum number of layers is 1");

        foreach (Layer layer in Layers)
        {
            if (layer.Neurons <= 0)
                throw new ArgumentException("neurons in each layer must be > 0");
        }

        if(Layers.Last().Activation != Layer.ActivFunction.LINEAR)
            throw new ArgumentException("last layer must be linear");
    }
  }
}
使用系统;
使用System.Collections.Generic;
使用System.Linq;
使用系统文本;
使用System.Collections.ObjectModel;
使用系统组件模型;
使用System.Windows;
使用System.Xml.Serialization;
名称空间快速测试
{
公共班级网络
{
公共类图层:INotifyPropertyChanged
{
公共枚举活动函数{线性、指数、ARCUSTANGENT}
私有字符串名称;
[XmlIgnore]
公共字符串名
{
得到
{
返回名称;
}
设置
{
名称=值;
RaiseProperty变更(“名称”);
}
}
[XmlAttribute]
公共ActivFunction激活{get;set;}
[XmlAttribute]
公共整数神经元{get;set;}
公共事件属性更改事件处理程序属性更改;
受保护的虚拟void RaisePropertyChanged(字符串propertyName)
{
if(PropertyChanged!=null)
{
PropertyChanged(这是新的PropertyChangedEventArgs(propertyName));
}
}
}
公共ObservableCollection层{get;set;}
公共网络()
{
层=新的ObservableCollection();
}
公共无效添加层(层)
{
int last=Layers.Count;
如果(上次>0)
{
Layers.Last().Name=“Layer”+Last+(隐藏)”;
}
layer.Name=“layer”+(last+1)+(output)”;
图层。添加(图层);
}
public void RemoveLayer(int索引)
{
如果(索引>=0&&index如果(layer.Neurons查看以下链接

编辑

您可能已经遵循了tut,但您遗漏了两件事,这就是导致问题的原因。首先,您正在尝试使用内置的BooleanToVisibility转换器,但我认为在您的场景中,这不会有帮助。您必须像教程中提到的那样包装一个自定义值转换器

public class BoolToVisibilityConverter : IValueConverter
  {
    public object Convert(object value, Type targetType,
      object parameter, System.Globalization.CultureInfo culture)
    {
      bool param = bool.Parse(parameter as string);
      bool val = (bool)value;

      return val == param ? Visibility.Visible : Visibility.Hidden;
    }

    public object ConvertBack(object value, Type targetType,
      object parameter, System.Globalization.CultureInfo culture)
    {
      throw new NotImplementedException();
    }
  }
你也必须像这样提到你的转换器

    <Setter Property="Visibility" Value="{Binding Path=IsSelected, 
        RelativeSource={RelativeSource FindAncestor, 
        AncestorType={x:Type ListViewItem}}, 
        Converter={StaticResource VisibilityOfBool}, ConverterParameter=False}" />


进行这些更改后,您就可以开始了……

查看以下链接

编辑

您可能已经遵循了tut,但您遗漏了两件事,这就是导致问题的原因。首先,您正在尝试使用内置的BooleanToVisibility转换器,但我认为在您的场景中,这不会有帮助。您必须像教程中提到的那样包装一个自定义值转换器

public class BoolToVisibilityConverter : IValueConverter
  {
    public object Convert(object value, Type targetType,
      object parameter, System.Globalization.CultureInfo culture)
    {
      bool param = bool.Parse(parameter as string);
      bool val = (bool)value;

      return val == param ? Visibility.Visible : Visibility.Hidden;
    }

    public object ConvertBack(object value, Type targetType,
      object parameter, System.Globalization.CultureInfo culture)
    {
      throw new NotImplementedException();
    }
  }
你也必须像这样提到你的转换器

    <Setter Property="Visibility" Value="{Binding Path=IsSelected, 
        RelativeSource={RelativeSource FindAncestor, 
        AncestorType={x:Type ListViewItem}}, 
        Converter={StaticResource VisibilityOfBool}, ConverterParameter=False}" />


进行这些更改后,您就可以开始了……

为什么不使用数据网格?您可以将其设置为类似列表的样式,并且它已经提供了编辑模式功能。您可以使用TemplateColumn来提供自定义显示和编辑视图。

为什么不使用数据网格?您可以将其设置为类似列表的样式,并且它已经提供了设置编辑模式功能。您可以使用TemplateColumn来提供自定义显示和编辑视图。

您可以发布转换器的代码吗?我怀疑存在问题,因为您正在发送显式转换器参数。我没有实现转换器-这是wpf中的默认值…您可以发布conv的代码吗erter?我怀疑问题是存在的,因为您正在发送显式的转换器参数。我没有实现转换器-这是wpf中的默认值…我做了所有这些,但仍然是一样的-我看到textblock和textboxI编辑了我的第一篇文章,发布了完整的xaml代码和转换器类,以及具有可观察集合边界的类到listview@biju链接被断开了我做了所有这些,但仍然是一样的-我看到textblock和textboxI编辑了我的第一篇文章,发布了完整的xaml代码和转换器类以及绑定了可观察集合的类listview@biju链接断了