If you have a custom control then I suggest you to override the method OnApplyTemplate and use GetTemplatedChild to find the Button, subscribe to its click and thats it except you will have to find the TextBox and set its Text inside the handler.
If you cannot do so for whatever reason here is a small trick how to make it still work
1.Take a look at this:
<resourcedictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="WPFControls.Generic"
xmlns:local="clr-namespace:WPFControls">
<setter property="Template">
<setter.value>
<controltemplate targettype="{x:Type local:MyChildControl}">
<border background="{TemplateBinding Background}">
SnapsToDevicePixels="True">
<stackpanel>
<textbox x:name="tbx1" xmlns:x="#unknown" />
<button content="{TemplateBinding Content}" click="OnClick" />
</stackpanel>
</border>
</controltemplate>
</setter.value>
</setter>
....
2.and add this code
public partial class Generic
{
public void OnClick(object sender, RoutedEventArgs e)
{
MyChildControl control = FindAncestor<mychildcontrol>((DependencyObject)sender);
TextBox tbx = control.Template.FindName("tbx1", control) as TextBox;
tbx.Text = "It works!";
}
public static T FindAncestor<t>(DependencyObject current) where T : DependencyObject
{
current = VisualTreeHelper.GetParent(current);
while (current != null)
{
if (current is T)
{
return (T)current;
}
current = VisualTreeHelper.GetParent(current);
};
return null;
}
}
3.This is mine MainWindow.xaml:
<window ....="">
<grid>
<local:mychildcontrol content="Click me!" xmlns:local="#unknown">