gpt4 book ai didi

c# - 通过单击行在 DataGrid 中选择一行

转载 作者:行者123 更新时间:2023-12-05 00:51:19 28 4
gpt4 key购买 nike

我有一个 DataGrid我试图通过选择行而不是单元格来更改所选项目。如下图所示,当我在单元格外单击时,该项目不会更新。

GIF  of user trying to select row on blank cell

<DataGrid x:Name="customerListBox" SelectedItem="{Binding SelectedCustomer, UpdateSourceTrigger=PropertyChanged}" SelectionMode="Single" IsReadOnly="True"  ItemsSource="{Binding Customers}"  Margin="10,57,10,10"  AlternationCount="2"  BorderThickness="1" SnapsToDevicePixels="True"  AutoGenerateColumns="False" BorderBrush="Black" Foreground="Black">
<DataGrid.Columns>
<DataGridTextColumn Binding="{Binding Id}" Header="Id"/>
<DataGridTextColumn Binding="{Binding Name}" Header="Name"/>
<DataGridTextColumn Binding="{Binding Phone}" Header="Phone"/>
<DataGridTextColumn Binding="{Binding Email}" Header="Email"/>
</DataGrid.Columns>
</DataGrid>

我能做的就是将最后一列的宽度设置为 *然而,这会使标题居中,并且在宽屏显示器上显示时看起来很困惑。
<DataGridTextColumn Binding="{Binding Email}" Width="*" Header="Email"/>

Column when set to *

最佳答案

我有解决此问题的解决方法,只需在最后一列后添加虚拟空列 宽度="*"

关于c# - 通过单击行在 DataGrid 中选择一行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44565272/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com