【发布时间】:2014-02-22 19:06:20
【问题描述】:
我正在创建一个 UI,我有两个 XAML 文件和两个 cs 文件:
Main.xaml
Library.xaml
Main.xaml.cs
Library.xaml.cs
我已经在Library.xaml 中声明了一个按钮并指定了一个名称my_button,我想在 Main.cs 中访问该按钮。
我该怎么做?
Library.xaml
<Style TargetType="Button">
<Setter Property="Template">
<ControlTemplate>
<Button x:Name=my_button Content="Click"></Button>
</ControlTemplate>
</Setter>
</Style>
【问题讨论】:
-
显示 xaml,我们可以看到这 2 个 xaml 的关系。
-
也许 TemplateBinding 和 CommandBinding 可以解决您的问题,而不是分配按钮的名称并从 main 访问它。
标签: c# .net wpf xaml controltemplate