XAML Behavior vs. EventTriggerBehavior Action #290
-
States
public class ShowAttachedFlyoutBehavior
: BehaviorBase<FrameworkElement>
{
protected override bool Initialize()
{
var result = ShowAttachedFlyout();
return result;
}
protected override bool Uninitialize()
{
HideAttachedFlyout();
return true;
}
private bool ShowAttachedFlyout()
{
if (AssociatedObject == null)
{
return false;
}
FlyoutBase.ShowAttachedFlyout(AssociatedObject);
return true;
}
private void HideAttachedFlyout()
{
FlyoutBase.GetAttachedFlyout(AssociatedObject).Hide();
}
} <Grid x:Name="AddNewGrid" ColumnDefinitions="70,Auto,20" Height="{Binding ElementName=NavigationPanel, Path=ActualHeight}">
<FlyoutBase.AttachedFlyout>
<MenuFlyout>
<MenuFlyoutItem Text="UDP"/>
<MenuFlyoutItem Text="TCP"/>
</MenuFlyout>
</FlyoutBase.AttachedFlyout>
<i:Interaction.Behaviors>
<core:EventTriggerBehavior EventName="Tapped" SourceObject="{Binding ElementName=AddNewGrid}">
<behaviors:ShowAttachedFlyoutBehavior/>
</core:EventTriggerBehavior>
</i:Interaction.Behaviors>
<TextBlock Grid.Column="1" Text="New" VerticalAlignment="Center"/>
</Grid>
ExpectationsAll should be without errors and warnings Result
Option infoIf you will remove the line Versions of CommunityToolkit.WinUI.UI.Behaviors: 7.1.2 |
Beta Was this translation helpful? Give feedback.
Answered by
michael-hawker
Nov 30, 2023
Replies: 1 comment 4 replies
-
@michael-hawker it steel doesn't work. The same error message. Maybe I'm doing something wrong? |
Beta Was this translation helpful? Give feedback.
4 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@limeniye your behavior setup doesn't make sense, I believe that's why you're having an issue. You'd probably get more info if you turned on mixed debugging, maybe?
It looks like you want to trigger an Action in response to the
EventTriggerBehavior
, so when tapped you open a flyout. For that you don't write a behavior, you useIAction
from the XAML Behaviors contracts. That's what allows EventTriggerBehavior to call things in response.Adding another behavior within there makes no sense. So, what's happening is your behavior is getting initialized right away and trying to open the flyout on load, which I assume is causing some issue within the platform code due to the timing of trying to …