-1

結果を呼び出し元(私の場合はユーザーがBing Mapで選択した場所)に返すCameraCaptureUI.CaptureFileAsyncのようなものを作成したいと思います(同じ質問がここで行われましたが、フルスクリーンUIまたはより完全なコード例が必要です)

次のユースケースを想定します。

  1. CallerPage1ナビゲート->CallerPage2(Frame.Navigate(typeof(CallerPage2))を介して)
  2. CallerPage2ナビゲート->LocationPickingPage(ここでも、Frame.Navigate(typeof(LocationPickingPage))を介して)<-ここでは、Frame.Navigateではなく他の何かである必要があります)
  3. ユーザーが場所を選択し、[完了]を押します-> CallerPage2に返される場所オブジェクト(Frame.Navigate(typeof(CallerPage2))を介して)

そして、ユーザーがCallerPage2を押すと、上記のナビゲーションモデルで期待されるLocationPickingPageに戻りますが、CallerPage1には移動しません。

これがCameraCaptureUI.CaptureFileAsyncの動作です。誰かがCaptureFileAsyncまたは使い慣れたメソッドの「舞台裏」を見て、次のように場所の選択を実行できるように実装する方法の例を提供するのを手伝ってくれるかもしれません。

Location location = await new LocationPickCaptureUI.CaptureLocationAsync();

どんな助けでもいただければ幸いです!

編集

したがって、誰かがナビゲーション履歴に影響を与えることなくページがデータを共有する方法に光を当てることができるかもしれません。私はAndroidのstartActivityForResultのようなものを探しています。

私はこの問題(msdn docs、さまざまな例、フォーラム、およびこれを含むさまざまなサイトの調査)に数日を費やしましたが、アプローチが見つからなかったので、自分で質問するときが来たと思います。

私が探している方法でページ間でデータを共有することは、明らかなことです。たぶん私は間違った見方をしていましたが、問題はまだ続いています。

そして、誰かが私の質問に反対票を投じた場合、私はまだこの問題について助けを必要としているので、あなたの心とあなたの知識の源を共有してください。

前もって感謝します

4

1 に答える 1

1

だから、最終的に私は適切な解決策を手に入れました、そして多分それは他の誰かに役立つかもしれません。

アイデアは、ポップアップオブジェクトを使用して、すべての画面に合わせるというものです(ただし、詳細はある種の魔法のように見えました:))

1つ:このシナリオでは、ポップアップのコンテンツを簡単に管理できるように、UserControl(VisualStudioでプロジェクトを右クリック->追加->新しいアイテム..->UserControl)テンプレートを使用しました。

C#の完全なソースは次のとおりです。

CustomCaptureUI.xaml:

<UserControl
x:Class="Family.CustomCaptureUI"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Family"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
d:DesignHeight="300"
d:DesignWidth="400"
x:Name="Root">

<Grid>
    <Border BorderBrush="Gray" BorderThickness="1">
        <Grid x:Name="Panel" Background="Gray">
            <Grid.ColumnDefinitions>
                <ColumnDefinition/>
                <ColumnDefinition/>
                <ColumnDefinition/>
            </Grid.ColumnDefinitions>
            <StackPanel Grid.Column="1" VerticalAlignment="Center">
                <TextBlock Text="New text" Foreground="LightGray" FontSize="18"/>
                <TextBox x:Name="ToDoText" Width="Auto" BorderBrush="Black" BorderThickness="1" VerticalAlignment="Center"/>
                <StackPanel Orientation="Horizontal" HorizontalAlignment="Right">
                    <Button x:Name="SubmitButton" Background="Gray" Content="Submit" HorizontalAlignment="Center"/>
                    <Button x:Name="CancelButton" Background="Gray" Content="Cancel" HorizontalAlignment="Center"/>
                </StackPanel>
            </StackPanel>
        </Grid>
    </Border>
</Grid>
</UserControl>

CustomCaptureUI.xaml.cs:

public sealed partial class CustomCaptureUI : UserControl
{
    public enum ResultStatuses
    {
        Canceled,
        Ok,
        None
    }

    public CustomCaptureUI()
    {
         _resultStatus = ResultStatuses.None;
        // force content's size to preferable value
        Root.Width = Window.Current.Bounds.Width;
        Root.Height = Window.Current.Bounds.Width * 0.3;
        // Init popup's Content
        _popup.Child = this;

        // Init popups's position
        _popup.SetValue(Canvas.LeftProperty, (Window.Current.Bounds.Width - Root.Width) * 0.5);
        _popup.SetValue(Canvas.TopProperty, (Window.Current.Bounds.Height - Root.Height) * 0.5);
    }

    public async Task<string> ShowDialog() 
    {
        string result = string.Empty;
        if (_semaphore != null) { DismissAddToDoPopup(); }

        // Init a Task for block the ShowDialog-method until user presses Cancel or Submit
        _semaphore = new Task(() => { });
        CancelButton.Click += (sender, e) =>
        {
            _resultStatus = ResultStatuses.Canceled;
            DismissAddToDoPopup();
        };
        SubmitButton.Click += (sender, e) =>
            {
                result = ToDoText.Text;
                _resultStatus = ResultStatuses.Ok;
                DismissAddToDoPopup();
            };

        ShowAddToDoPopup();

        // actual blocking of ShowDialog
        await _semaphore;
        return result;
    }

    public void DismissDialog() 
    {
        _resultStatus = ResultStatuses.Canceled;
        DismissAddToDoPopup();
    }

    private void ShowAddToDoPopup()
    {
        ToDoText.Text = string.Empty;
        _popup.IsOpen = true;
    }

    private void DismissAddToDoPopup()
    {
        if (_semaphore != null) 
        { 
            // starts the task and allows awaited ShowDialog-method to be released
            // after _semaphore is finishing
            _semaphore.Start();
            _semaphore = null;
        }
        _popup.IsOpen = false;
    }

    public ResultStatuses ResultStatus
    {
        get { return _resultStatus; }
    }


    private Popup _popup = new Popup();
    private Task _semaphore;
    private ResultStatuses _resultStatus;


}

そして、次のように使用できます。

        var dialog = new CustomCaptureUI();
        string result = await dialog.ShowDialog();
        if (dialog.ResultStatus == AddToDoDialog.ResultStatuses.Ok) 
        {
            // Useful stuff
            if (!string.IsNullOrWhiteSpace(result))
            {
               ...
            }
        }

それが誰かの時間を少し節約できることを願っています

于 2012-10-11T13:27:15.857 に答える