views:

10

answers:

1

Hi, I have a ContentControl element whose ContentTemplate is determined at run time from the Resource Dictionary. In the datatemplate I have a visual (Convas) and what I want is to also have a button in datatemplate which when clicked should print the visual element(canvas). As I said that the DateTemplate is inside the Resource Dictionary so How can I write a Code on Click Event of that button and where it should be?

Any response would be much appreciated.

A: 

Sounds like you can use the Button.Click attached event. Just add it to the ContentControl.

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

and the handler:

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

If you have multiple buttons in your template, you can use e.Source to figure it out. And I think you can use MouseButtonEventArgs instead.

TheSean