【问题标题】:Print Button inside DataTemplate? How to write codeDataTemplate 中的打印按钮?如何编写代码
【发布时间】:2010-07-05 15:40:18
【问题描述】:

我有一个 ContentControl 元素,它的 ContentTemplate 是在运行时从资源字典中确定的。在数据模板中,我有一个视觉(Convas),我想要的是在数据模板中也有一个按钮,单击该按钮应打印视觉元素(画布)。 正如我所说,DateTemplate 位于资源字典中,那么如何在该按钮的单击事件上编写代码以及它应该在哪里?

任何回复将不胜感激。

【问题讨论】:

    标签: wpf button resources resourcedictionary


    【解决方案1】:

    听起来您可以使用 Button.Click 附加事件。只需将其添加到 ContentControl。

    <ContentControl 
        Button.Click="Button_Click" 
        ContentTemplate="<template with a button>"   
    />
    

    和处理程序:

    private void Button_Click(object sender, RoutedEventArgs e)
    {
    }
    

    如果您的模板中有多个按钮,您可以使用e.Source 来解决。而且我认为您可以改用MouseButtonEventArgs

    【讨论】:

      猜你喜欢
      • 2011-04-09
      • 2014-05-01
      • 2013-10-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-03-03
      • 2012-01-29
      • 1970-01-01
      相关资源
      最近更新 更多