我发现在XAML中定义了交互行为时,我的应用程序崩溃了。
弹出控件可以有交互行为吗?
XAML:
<AppBarButton Icon="Find" Label="Find">
<Button.Flyout>
<Flyout x:Name="SearchFlyout">
<Interactivity:Interaction.Behaviors>
<Core:EventTriggerBehavior EventName="Opened">
<behaviors:FlyoutOpenedAction />
</Core:EventTriggerBehavior>
</Interactivity:Interaction.Behaviors>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
<TextBox x:Name="Searchbox" PlaceholderText="contact's name" Width="250"
IsTextPredictionEnabled="False"
IsSpellCheckEnabled="False"
VerticalAlignment="Center">
<Interactivity:Interaction.Behaviors>
<Core:EventTriggerBehavior EventName="KeyUp">
<behaviors:FilterContactAction />
</Core:EventTriggerBehavior>
</Interactivity:Interaction.Behaviors>
</TextBox>
</StackPanel>
</Flyout>
</Button.Flyout>
</AppBarButton>
代码:
public class FlyoutOpenedAction : DependencyObject, IAction
{
public object Execute(object sender, object parameter)
{
var searchBox = ResourceLocator.Instance[typeof(TextBox)] as TextBox;
searchBox.Text = string.Empty;
return null;
}
}