我猜你错过了设置TargetObject
值。
<Button Content="click me"
HorizontalAlignment="Center"
VerticalAlignment="Center">
<I:Interaction.Behaviors>
<Core:EventTriggerBehavior EventName="Click" >
<Core:GoToStateAction TargetObject="{Binding ElementName=MySplitView}"
StateName="OpenOverlayLeft"/>
</Core:EventTriggerBehavior>
</I:Interaction.Behaviors>
</Button>
更新
使用 4 个按钮查看行为,这些按钮放置在内部SplitView.Content
和SplitView.Pane
外部。一切都很好。
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<SplitView x:Name="MySplitView"
PaneBackground="Gray"
DisplayMode="CompactOverlay"
IsPaneOpen="True"
CompactPaneLength="50"
OpenPaneLength="280">
<SplitView.Pane>
<Grid>
<Button Content="close inside"
HorizontalAlignment="Center"
VerticalAlignment="Center">
<i:Interaction.Behaviors>
<core:EventTriggerBehavior EventName="Click" >
<core:GoToStateAction TargetObject="{Binding ElementName=MySplitView}"
StateName="Closed"/>
</core:EventTriggerBehavior>
</i:Interaction.Behaviors>
</Button>
</Grid>
</SplitView.Pane>
<SplitView.Content>
<Grid>
<Button Content="open inside"
HorizontalAlignment="Center"
VerticalAlignment="Center">
<i:Interaction.Behaviors>
<core:EventTriggerBehavior EventName="Click">
<core:GoToStateAction TargetObject="{Binding ElementName=MySplitView}"
StateName="OpenOverlayLeft"/>
</core:EventTriggerBehavior>
</i:Interaction.Behaviors>
</Button>
</Grid>
</SplitView.Content>
</SplitView>
<Grid Grid.Column="1"
Background="Aquamarine">
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Button Content="open outside"
HorizontalAlignment="Center"
VerticalAlignment="Center">
<i:Interaction.Behaviors>
<core:EventTriggerBehavior EventName="Click">
<core:GoToStateAction TargetObject="{Binding ElementName=MySplitView}"
StateName="OpenOverlayLeft"/>
</core:EventTriggerBehavior>
</i:Interaction.Behaviors>
</Button>
<Button Content="close outside"
Grid.Column="1"
HorizontalAlignment="Center"
VerticalAlignment="Center">
<i:Interaction.Behaviors>
<core:EventTriggerBehavior EventName="Click" >
<core:GoToStateAction TargetObject="{Binding ElementName=MySplitView}"
StateName="Closed"/>
</core:EventTriggerBehavior>
</i:Interaction.Behaviors>
</Button>
</Grid>
</Grid>
看看它是如何工作的: