<Style x:Key="abc" TargetType="{x:Type Window}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Window}">
<button x:name="btn">my button!!</button>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
...
<Window ... Style="{StaticResource styleMainWindow}">
How can i use the button btn?
come up to your expectations,
MessageBox.Show(this.btn1.name);
was occured an error at compile time. and also btn1 didn’t show up in intelisense.
Try the FindName method on the ControlTemplate class.
Assuming this is your Control’s context: