microsoft / XamlBehaviors

This is the official home for UWP XAML Behaviors on GitHub.
MIT License
700 stars 112 forks source link

NavigateToPageAction in Nested Frame? #153

Open seanocali opened 5 years ago

seanocali commented 5 years ago

Is there a way to do this? I tried the code below but it just targeted the root frame.

    <Grid Width="800" Height="600" Background="Blue">
        <Frame Width="400" Height="300" Background="Green">
            <Interactivity:Interaction.Behaviors>
                    <Interactions:EventTriggerBehavior EventName="Click" SourceObject="{Binding ElementName=button}">
                    <Interactions:NavigateToPageAction TargetPage="XAMLBehaviorsSample.NavigatePageSample"/>
                    </Interactions:EventTriggerBehavior>
                </Interactivity:Interaction.Behaviors>
        </Frame>
        <Button x:Name="button" VerticalAlignment="Bottom" />
    </Grid>

EDIT: I looked at the code. It walks up the visual tree looking for the nearest INavigate parent, but it only does this if there is no root frame (INavigate navigateElement = Window.Current.Content as INavigate), which means it will never do this since there's always a root frame (right?). IMHO it should always prefer the closest INavigate parent, not the root one--or at least have a dependency property setting this as a preference.

nigel-sampson commented 5 years ago

Inverting the behavior would be a breaking change, but adding a configurable option wouldn't.