Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/12.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/19.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_Xaml_Listbox - Fatal编程技术网

C# WPF在列表框内启用高亮显示、复制和粘贴

C# WPF在列表框内启用高亮显示、复制和粘贴,c#,wpf,xaml,listbox,C#,Wpf,Xaml,Listbox,我有一个要在菜单上显示的字符串列表。我使用了一个列表框,它的工作原理就是它不会让我高亮显示或复制/粘贴 这是我的XAML <Grid> <Grid.ColumnDefinitions> <ColumnDefinition Width="500"/> <ColumnDefinition Width="500"/> </Grid.ColumnDefinitions> <Grid.

我有一个要在菜单上显示的字符串列表。我使用了一个列表框,它的工作原理就是它不会让我高亮显示或复制/粘贴

这是我的XAML

<Grid>
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="500"/>
        <ColumnDefinition Width="500"/>
    </Grid.ColumnDefinitions>
    <Grid.RowDefinitions>
        <RowDefinition Height="450"/>
        <RowDefinition Height="318"/>
    </Grid.RowDefinitions>



    <ListBox Grid.Row="1" Grid.Column="1" x:Name="uiOCRData" />



</Grid>
这是我的C语言

List<string> lines = new List<string>();
uiOCRData.ItemsSource = lines;
谢谢你的帮助

必须使用ListBox.ItemTemplate,以便在ListBox中包含控件

由于您希望能够选择文本等,最好的选择是使用文本框

然后可以绑定到类的任意一个选定属性,如下所示:

public class Data
{
    public int Id { get; set; }
    public string Name { get; set; }
}
<ListBox Grid.Row="0" Name="uiOCRData">
    <ListBox.ItemTemplate>
        <DataTemplate>
            <TextBox Width="100" Text="{Binding Name}"/>
        </DataTemplate>
    </ListBox.ItemTemplate>
</ListBox>

使用textbox作为Listbox.itemtemplate当我使用这个时,我的ui中没有出现任何东西。如果您使用列表作为ItemsSource,那么绑定必须完全如我所示:
<ListBox Grid.Row="0" Name="uiOCRData">
    <ListBox.ItemTemplate>
        <DataTemplate>
            <TextBox Width="100" Text="{Binding Name}"/>
        </DataTemplate>
    </ListBox.ItemTemplate>
</ListBox>