2013-11-26 80 views
1

我試圖創建的Windows Phone工具包的DatePicker & TimePicker一個彈出窗口,用下面的XAML:如何在包含它們的Popop上顯示DatePicker&TimePicker控件?

<Popup x:Name="MyPopup"> 

    <Border BorderThickness="2" Margin="10" BorderBrush="{StaticResource PhoneAccentBrush}"> 

     <StackPanel> 

      <toolkit:DatePicker Name="datePicker" /> 
      <toolkit:TimePicker Name="timePicker"/> 

     </StackPanel> 

    </Border> 
</Popup> 

這工作,但我每次單擊它們中,他們彈出下,例如渲染

enter image description here

在顯示的DatePicker或TimePicker我想不出任何辦法隱藏彈出。

我已經嘗試設置控件的Z-指數比彈出更大,具體如下:

void timePicker_GotFocus(object sender, RoutedEventArgs e) 
{ 
    Canvas.SetZIndex(timePicker, Canvas.GetZIndex(MyPopup) + 1); 
} 

我也試着隱藏彈出式與

void timePicker_GotFocus(object sender, RoutedEventArgs e) 
{ 
    Popup.IsOpen = false; 
} 

但這會關閉彈出窗口和TimePicker/DatePicker。

有什麼方法可以查看彈出控件頂部的DatePicker/TimePicker控件嗎?

+0

你覺得這樣的事情? http://sdrv.ms/1bVpamc –

+0

是的,就像那樣。請提供這個(或者至少它的重要部分)作爲答案,我會接受它! – DaveDev

回答

1

Sample project.

XAML

<Border 
     Background="{StaticResource PhoneChromeBrush}" 
     BorderThickness="2" 
     Margin="10" 
     BorderBrush="{StaticResource PhoneAccentBrush}"> 

     <StackPanel> 

      <toolkit:DatePicker 
       Tap="DatePickerTap" /> 

      <toolkit:TimePicker 
       Tap="DatePickerTap" /> 

     </StackPanel> 

    </Border> 
</Popup> 

代碼背後

private bool pickerIsOpen = false; 

// constructor 
public MainPage() 
{ 
    InitializeComponent(); 

    this.Loaded += this.MainPageLoaded; 
} 

// page loaded 
private void MainPageLoaded(object sender, RoutedEventArgs e) 
{ 
    if (this.pickerIsOpen) 
    { 
     this.MyPopup.IsOpen = true; 
     this.pickerIsOpen = false; 
    } 
} 

// date/time picker tap 
private void DatePickerTap(object sender, System.Windows.Input.GestureEventArgs e) 
{ 
    this.pickerIsOpen = true; 
} 
相關問題