データテンプレートのボタンにクリックイベントを追加したい。いくつかのコードがあります:
var temp = (DataTemplate)XamlReader.Load(
new MemoryStream(Encoding.Default.GetBytes(
@"<DataTemplate xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation' xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'><Button><TextBlock Text='1' TextAlignment='Center'/></Button></DataTemplate>"
)));
var button = temp.LoadContent() as Button;
button.Click += (sender, args) =>
{
MessageBox.Show("123");
};
return temp;
そのため、ボタンをクリックしても何も起こりません。私は何が欠けていますか?