【发布时间】:2016-08-01 16:50:34
【问题描述】:
这是我的依赖属性:
public static readonly DependencyProperty ButtonTapSoundProperty = DependencyProperty.RegisterAttached("ButtonTapSound", typeof (Uri), typeof (ButtonDependencyObject), new PropertyMetadata(default(Uri), UriChanged));
然后我像这样使用它:
<Button buttonDependencyObject:ButtonDependencyObject.ButtonTapSound="{Binding ElementName=TapSound}" ... />
这在设计时和运行时都能完美运行。
但是,如果我在这样的控件模板中定义它:
<ControlTemplate x:Name="TapSound" TargetType="Button">
<Button buttonDependencyObject:ButtonDependencyObject.ButtonTapSound="{Binding ElementName=TapSound}" ... />
</ControlTemplate>
它在运行时有效,但在 Visual Studio 设计器中无效
【问题讨论】:
-
只是一个问题:为什么还要在 Button 的 ControlTemplate 中放置另一个按钮?
-
你为什么在乎它在设计器中不起作用?
-
@lokusking 它发生在任何控件模板中。
-
@MichaelThePotato 因为我愿意。这很烦人。
-
到底发生了什么?您希望播放的声音吗?你如何在设计时触发它?你在设计器中遇到错误吗?
标签: c# visual-studio windows-runtime winrt-xaml