1
我創建一個UI和我有兩個XAML文件和兩個CS文件:訪問在cs文件XAML文件的元素在WPF
Main.xaml
Library.xaml
Main.xaml.cs
Library.xaml.cs
我有在Library.xaml
中聲明瞭一個Button並給出了一個名稱my_button
並且我想在Main.c中訪問該Button。
我怎麼能這樣做?
Library.xaml
<Style TargetType="Button">
<Setter Property="Template">
<ControlTemplate>
<Button x:Name=my_button Content="Click"></Button>
</ControlTemplate>
</Setter>
</Style>
顯示xaml,我們可以看到這兩個xaml是如何關聯的。 –
也許TemplateBinding和CommandBinding可以解決你的問題,而不是分配按鈕的名字並從main訪問它。 –