1

XAMLユーザーコントロール内では、Frameオブジェクトはnullです。

this.Frame.Navigate(typeof(FaxPropertiesPage));

Windows 8 XAMLユーザーコントロールを使用してページ間を移動するにはどうすればよいですか?XAMLページのCallistoFlyout内にコントロールを配置しました。

下の検索ボタンは、ユーザーを別のXAMLページに移動する必要があります。

ここに画像の説明を入力してください

4

3 に答える 3

5

app.xaml.csのコードを正常に使用しました

Frame frame = Window.Current.Content as Frame;

次に、標準のナビゲートコードを使用しました。

于 2012-12-31T10:15:23.153 に答える
1

良い方法とそうでない方法があります:

どちらもナビゲーションサービスから始まります。

public interface INavigationService
{
    bool CanGoBack { get; }
    void GoBack();
    void GoForward();
    bool Navigate<T>(object parameter = null);
    bool Navigate(Type source, object parameter = null);
    void ClearHistory();
    event EventHandler<NavigatingCancelEventArgs> Navigating;
}

public class NavigationService : INavigationService
{
    private readonly Frame _frame;

    public NavigationService(Frame frame)
    {
        _frame = frame;
        frame.Navigating += FrameNavigating;
    }

    #region INavigationService Members

    public void GoBack()
    {
        _frame.GoBack();
    }

    public void GoForward()
    {
        _frame.GoForward();
    }

    public bool Navigate<T>(object parameter = null)
    {
        Type type = typeof (T);

        return Navigate(type, parameter);
    }

では、フレームはどこで入手できますか?App.xaml.csで

protected async override void OnLaunched(LaunchActivatedEventArgs args)
{
    // Do not repeat app initialization when already running, just ensure that
    // the window is active
    if (args.PreviousExecutionState == ApplicationExecutionState.Running)
    {
        Window.Current.Activate();
        return;
    }

    // Create a Frame to act as the navigation context and navigate to the first page
    var rootFrame = new Frame();
    if (DesignMode.DesignModeEnabled)
        SimpleIoc.Default.Register<INavigationService, DesignTimeNavigationService>();
    else
        SimpleIoc.Default.Register<INavigationService>(() => new NavigationService(rootFrame));

ここではMVVMLightを使用しています。これにより、すべてのビューモデルが依存性注入を使用して作成され、それらのサービスが注入されるため、作業が楽になります。

MVVM Lightのようなものを使用しておらず、コードビハインドに依存している場合でも、これを機能させることができます。ナビゲーションサービスを静的にするだけです。

  public class NavigationService : INavigationService
    {
        public static INavigationService Current{
get;set;}

blah blah blah
}

そして、App.xaml.csを次のように変更します。

    protected async override void OnLaunched(LaunchActivatedEventArgs args)
    {
        // Do not repeat app initialization when already running, just ensure that
        // the window is active
        if (args.PreviousExecutionState == ApplicationExecutionState.Running)
        {
            Window.Current.Activate();
            return;
        }

        // Create a Frame to act as the navigation context and navigate to the first page
        var rootFrame = new Frame();
        NavigationService.Current= new NavigationService(rootFrame));
}

そして、次のように言うことで、アプリのどこからでもメインフレームにアクセスできます。

NavigationService.Current.Navigate<MyView>();
于 2012-10-14T14:01:19.180 に答える
1

単純なコード(100%効率的ではない場合があります)は次のとおりです。

フレームframe=new Frame(); frame.Navigate(typeof(ExerciseAddPage)

于 2012-12-27T02:23:18.983 に答える