User control navigation in win 7 phone

I cannot call the navigation service from a user control. even when I create one event handler on the main page to call a navigation service that is not working.

Can you help me?

+3
source share
1 answer

I think I see the problem, but, as Austin said, there is not much in your original description. It looks like you are trying to access the NavgationService (which is PhoneApplicationPage ) from within the UserControl that you host on this page.

API, . -, PhoneApplicationFrame ( ) :

var frame = App.Current.RootVisual as PhoneApplicationFrame;
frame.Navigate(new Uri("/TargetPage.xaml", UriKind.Relative));

VisualTreeHelper, :

var page = GetParentOfType<PhoneApplicationPage>(this); // this is your user control


private static T GetParentOfType<T>(DependencyObject item) where T : DependencyObject
{
    if (item == null) throw new ArgumentNullException("item");
    T result;
    var parent = VisualTreeHelper.GetParent(item);
    if (parent == null) return null;
    else if (parent.GetType().IsSubclassOf(typeof(T))
    {
          result = (T)parent;
    }
    else result = GetParameterOfType<T>(parent);
    return result;
}

, VisualTree , , , NavigationContext ..

, ( .)

+7

Source: https://habr.com/ru/post/1792717/


All Articles