【问题标题】:DataGrid Cell with text and button带有文本和按钮的 DataGrid 单元格
【发布时间】:2014-01-16 22:38:44
【问题描述】:

在 DataGrid 的单元格中有一个“添加”按钮,然后是一个文本块显示数量。当用户单击“添加”按钮时,它会在数量上加一。我很难弄清楚如何创建文本块。这是我的牢房;

<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
    <StackPanel Orientation="Horizontal">
        <Button Content="+" Click="addQTYButton_Click"/>
        <TextBlock Text="{Binding qty}"/>

    </StackPanel>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>

【问题讨论】:

  • 有什么问题?您提供的 XAML 应该可以工作,具体取决于您正在尝试执行的操作。

标签: c# wpf datagrid


【解决方案1】:

最好的解决方案是不使用 Click 事件和代码隐藏。

改用命令并在您的ViewModel 中更改调用命令时TextBlock 绑定的字符串...

如果您坚持使用事件和代码隐藏,只需将其命名为 TextBlock,您就可以在事件处理程序中使用它以您喜欢的任何方式对其进行操作...

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-09-15
    • 2015-05-05
    • 1970-01-01
    • 2021-05-10
    • 2018-04-16
    • 2022-12-30
    相关资源
    最近更新 更多