gpt4 book ai didi

.net - 使用 WPF 的网格中的按钮数组

转载 作者:行者123 更新时间:2023-12-01 11:52:39 24 4
gpt4 key购买 nike

下面的代码是在 .net 4 中的 WPF 中,它显示了一个开始时为空的网格。当我添加元素时,它会在最后两列分别显示带有进度条和“发送”按钮的行。当我再添加一行时,会出现一个进度条和按钮。但是如果我点击按钮,所有按钮都使用相同的事件处理程序。如何使每个进度条和行中的按钮不同?

<Window x:Class="ObservableCollection.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Grid>
<DataGrid Name="DataGrid" ItemsSource="Binding DataGrids" AutoGenerateColumns="False" RowHeight="30"
ColumnWidth="100" ColumnHeaderHeight="50" HeadersVisibility="Column" AlternatingRowBackground="LightBlue"
CanUserAddRows="False" Background="Transparent" RowBackground="Transparent" BorderBrush="Gray"
CellStyle="{StaticResource Body_Conternt_DataGrid_Centering}"
IsReadOnly="True" Margin="49,66,45,62" Opacity="1" >
<DataGrid.Columns>
<DataGridTextColumn Width="*" Header="UID" Binding="{Binding Uid}" />
<DataGridTextColumn Width="*" Header="Type" Binding="{Binding Type}" />
<DataGridTextColumn Width="*" Header="Channel Type" Binding="{Binding ChannelType}" />
<DataGridTextColumn Width="*" Header="Certificate" Binding="{Binding Certificate}" />
<DataGridTextColumn Width="*" Header="Life Cycle State" Binding="{Binding LifeCycle}" />
<DataGridTextColumn Width="*" Header="Status" Binding="{Binding Status}" />
<DataGridTextColumn Width="*" Header="Image UID" Binding="{Binding ImageUid}" />

<DataGridTemplateColumn Width="*">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<ProgressBar Height="20" Value="{Binding Progress}"></ProgressBar>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>

<DataGridTemplateColumn Width="*">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Button Name="btnSend" Click="btnSend_Click">Send</Button>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
</DataGrid.Columns>
</DataGrid>
</Grid>
</Window>

最佳答案

我正在考虑将 Tag 属性绑定(bind)到您要发送的任何内容的唯一键,

<Button Tag="{Binding ID}> 

并在您的发送事件中取回标签值..

var button = sender as Button;
var tag = button.Tag;

关于.net - 使用 WPF 的网格中的按钮数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9901145/

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