C# XAML-如何在页面或应用程序级别声明行为
我已使用Blend将以下行为添加到WinPhone8.1应用程序中的自定义用户控件中:C# XAML-如何在页面或应用程序级别声明行为,c#,wpf,xaml,windows-phone-8.1,C#,Wpf,Xaml,Windows Phone 8.1,我已使用Blend将以下行为添加到WinPhone8.1应用程序中的自定义用户控件中: <Interactivity:Interaction.Behaviors> <Core:EventTriggerBehavior x:Name="Pressed" EventName="PointerPressed"> <Core:ChangePropertyAction PropertyName="Background"&
<Interactivity:Interaction.Behaviors>
<Core:EventTriggerBehavior x:Name="Pressed" EventName="PointerPressed">
<Core:ChangePropertyAction PropertyName="Background">
<Core:ChangePropertyAction.Value>
<SolidColorBrush Color="#FF75807F"/>
</Core:ChangePropertyAction.Value>
</Core:ChangePropertyAction>
</Core:EventTriggerBehavior>
<Core:EventTriggerBehavior x:Name="Released" EventName="PointerCaptureLost">
<Core:ChangePropertyAction PropertyName="Background"/>
</Core:EventTriggerBehavior>
</Interactivity:Interaction.Behaviors>
这很好,而且效果很好。我希望将此代码移动到App.xaml中,以便将行为添加到不同的网格中
我将“using”语句移动到App.xaml文件:
xmlns:interactive=“using:Microsoft.Xaml.interactive”xmlns:Core=“using:Microsoft.Xaml.Interactions.Core”
以及样式:
<Style TargetType="Grid" x:Key="ClickableGrid2" >
<Interactivity:Interaction.Behaviors>
<Core:EventTriggerBehavior x:Name="Pressed" EventName="PointerPressed">
<Core:ChangePropertyAction PropertyName="Background">
<Core:ChangePropertyAction.Value>
<SolidColorBrush Color="#FF75807F"/>
</Core:ChangePropertyAction.Value>
</Core:ChangePropertyAction>
</Core:EventTriggerBehavior>
<Core:EventTriggerBehavior x:Name="Released" EventName="PointerCaptureLost">
<Core:ChangePropertyAction PropertyName="Background"/>
</Core:EventTriggerBehavior>
</Interactivity:Interaction.Behaviors>
我还引用了网格中的样式:
<Grid x:Name="QuestionGrid" Background="White" Style="{StaticResource ClickableGrid2}">
controls omitted...
</Grid>
忽略控件。。。
代码可以编译,但当我在调试模式下运行时,一旦应用程序启动,就会出现以下错误:
无法反序列化XBF元数据类型列表,因为在命名空间“%0”中找不到“%1”。[行:0位置:0]
没有内在的例外。没有太多细节,但我假设错误与我添加到App.xaml文件中的“using”语句有关-但我不确定
我假设可以在应用程序级别添加行为,但谷歌没有返回任何这样做的好例子。我在应用程序级别添加了简单的样式,效果很好
我的问题是:我可以这样添加行为吗?如果可以,我会错在哪里?你确定可以将行为添加到样式中吗?我一点也不确定-这是我尝试让“全局”行为正常工作,没有编译时错误,所以我想我已经解决了-直到我开始运行应用程序。一定有某种方式可以让人有“全球”行为,但我可以想出来——我现在把它们放在了列表中的本地位置。
<Grid x:Name="QuestionGrid" Background="White" Style="{StaticResource ClickableGrid2}">
controls omitted...
</Grid>