Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/visual-studio-code/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Windows 8 用于将结果返回给调用者的选取页面_Windows 8_Microsoft Metro - Fatal编程技术网

Windows 8 用于将结果返回给调用者的选取页面

Windows 8 用于将结果返回给调用者的选取页面,windows-8,microsoft-metro,Windows 8,Microsoft Metro,我想创建类似CameraCaptureUI.CaptureFileAsync的东西,它将结果返回给调用者(在我的例子中,用户通过bing地图选择的位置) (问了同样的问题,但我仍然需要全屏UI或更完整的代码示例) 假设下一个用例: CallerPage1 Navigate->CallerPage2(通过Frame.Navigate(typeof(CallerPage2))) CallerPage2 Navigate->LocationPickingPage(再次通过Frame.Navigate(

我想创建类似CameraCaptureUI.CaptureFileAsync的东西,它将结果返回给调用者(在我的例子中,用户通过bing地图选择的位置) (问了同样的问题,但我仍然需要全屏UI或更完整的代码示例)

假设下一个用例:

  • CallerPage1 Navigate->CallerPage2(通过Frame.Navigate(typeof(CallerPage2)))
  • CallerPage2 Navigate->LocationPickingPage(再次通过Frame.Navigate(typeof(LocationPickingPage))返回给CallerPage2的位置对象 (通过Frame.Navigate(typeof(CallerPage2)))
  • 现在,如果用户按回CallerPage2,他/她将被导航回LocationPickingPage,这在上述导航模型中是应该的,但我不会将他/她导航到CallerPage1

    这就是CameraCaptureUI.CaptureFileAsync的行为。 也许有人可以帮助了解CaptureFileAsync或熟悉的方法的“幕后”,并提供一些示例,说明如何实现它,以便可以像这样执行位置拾取:

    Location location = await new LocationPickCaptureUI.CaptureLocationAsync();
    
            var dialog = new CustomCaptureUI();
            string result = await dialog.ShowDialog();
            if (dialog.ResultStatus == AddToDoDialog.ResultStatuses.Ok) 
            {
                // Useful stuff
                if (!string.IsNullOrWhiteSpace(result))
                {
                   ...
                }
            }
    
    任何帮助都将不胜感激

    编辑

    所以,也许有人可以解释一下页面如何在不影响导航历史的情况下共享数据。我只是在寻找类似android的startActivityForResult的东西

    我花了几天时间研究这个问题(msdn文档,研究不同的例子,论坛和不同的网站,包括这一个),但没有找到任何方法,所以我认为是时候问自己的问题了

    以我正在寻找的方式在页面之间共享数据应该是显而易见的。也许我是以错误的方式寻找的,但问题仍然是persist的

    如果有人投票否决我的问题,请分享你的想法和你的知识来源,因为我在这个问题上仍然需要帮助


    提前感谢

    所以,我终于找到了一个合适的解决方案,也许它对其他任何人都有帮助

    其想法是使用弹出对象并适合所有屏幕(不过细节似乎有点神奇:)

    有一件事:我使用了UserControl(在VisualStudio中右键单击project->Add->new item..->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>
    
    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;
    
    
    }
    
    希望它能节省一些人的时间