<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}">
如何使用按鈕btn
?如何在模板中使用控件?
來達到你的期望,
MessageBox.Show(this.btn1.name);
在編譯時發生錯誤。並且btn1也沒有出現在intelisense中。
你想創建一個無視的控制或用戶控件? –