2012-10-02 50 views
-1

我想創建類似CameraCaptureUI.CaptureFileAsync的東西,它會將結果返回給調用者(用戶通過在我的情況下使用bing地圖挑選的位置) (同一問題被問到here但我仍然需要全屏UI或多個完整的代碼示例)挑選返回結果給調用者的頁面

假設下一次使用的情況下:

  1. CallerPage1 Navigate-> CallerPage2(通過Frame.Navigate(typeof運算(CallerPage2)))
  2. CallerPage2導航 - > LocationPickingPage(a通過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文檔,研究不同的例子,論壇和包括這一個不同的網站),並沒有找到任何方法,所以我認爲是時候問自己的問題。

按照我尋找的方式在頁面之間共享數據應該是顯而易見的。也許我在看錯方法,但問題仍然存在。

如果有人回答我的問題,請分享您的想法和您的知識來源,因爲我仍然需要關於此問題的幫助。

在此先感謝

回答

1

所以,最後我有一個合適的解決方案,也許它可以幫助別人。

的想法是使用彈出對象,適合所有屏幕(但細節看起來像是某種魔力:))

一兩件事:我使用的用戶控件(在Visual Studio中右鍵單擊項目 - >添加 - >新項目... - >用戶控件)作爲模板,在這種情況下很容易地管理彈窗的內容

這裏是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)) 
      { 
       ... 
      } 
     } 

希望它可以救一個人的時間有點

相關問題