简体   繁体   English

如何在C#中向带有GridView的ListView添加文本框列-WPF动态地?

[英]How to add a column of textboxes to a ListView w/ GridView in C# - WPF dymanically?

I've got a ListView defined in XML: 我有一个用XML定义的ListView:

    <ListView 
        x:Name="lvFuellmengenDetails"
        HorizontalAlignment="Center" 
        Height="570" 
        FontSize="30"
        Margin="10,85,10,0" 
        VerticalAlignment="Top" 
        HorizontalContentAlignment="Center"
        Width="572">

In the code behind I set the GridView as a view to the ListView to be able to add some columns 在后面的代码中,我将GridView设置为ListView的视图,以便能够添加一些列

var gridView = new GridView();
        this.lvFuellmengenDetails.View = gridView;
        gridView.Columns.Add(new GridViewColumn
        {
            Header = "Nummer",
            Width = 200,
            DisplayMemberBinding = new Binding("Nummer")
        });
        gridView.Columns.Add(new GridViewColumn
        {
            Header = "Wert",
            Width = 200,

            DisplayMemberBinding = new Binding("Wert")
        });

I need another Column that should be editable in every line (eg Textboxes) - defined not in XML, but in C# code) 我需要在每一行(例如文本框)中都应该可编辑的另一列-不是用XML定义,而是用C#代码定义)

If that is not possible: is there a way to detect a certain line is clicked? 如果不可能:是否有检测到单击特定行的方法? I looked for an Event like "ItemClicked" but couldnt find any. 我寻找了类似“ ItemClicked”的事件,但找不到任何事件。

Then I could open a DialogBox and change the label instead of using textboxes. 然后,我可以打开一个对话框并更改标签,而不使用文本框。 Thanks for your help. 谢谢你的帮助。

To archive what you want, you have to either build the DataTemplate or get the resource and assign that onto the columns ItemTemplate 要存档所需的内容,您必须构建DataTemplate或获取资源并将其分配到ItemTemplate列上

it is more or less the same as if you would use normal XAML 它与您将使用普通XAML大致相同

as the DataTemplate probably wont change, you probably want to create the DataTemplate in XAML and then just load it from the resources 由于DataTemplate可能不会更改,因此您可能想在XAML中创建DataTemplate,然后从资源中加载它

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

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