从弹出窗口打开DatePicker

时间:2012-01-20 11:28:08

标签: windows-phone-7

我想从弹出窗口中打开一个DatePicker。单击日期选择器时,日期输入页面(带有微调器的页面)将在弹出窗口后面打开。

在选择日期后,DatePicker如何查看弹出窗口并返回到它?

这就是我打开弹出窗口的方式:

private void btnShowBuyNow_Click(object sender, RoutedEventArgs e)
    {
        Popup buyNowScreen;
        buyNowScreen = new Popup();
        buyNowScreen.Child = 
            new BuyNowScreen
                ("Buy this application and get rid of the ads!");
        buyNowScreen.IsOpen = true;
        buyNowScreen.VerticalOffset = 100;
        buyNowScreen.HorizontalOffset = 25;
        buyNowScreen.Closed += (s1, e1) =>
            {
                // Add you code here to do something 
                // when the Popup is closed
            };
    }

弹出窗口的xaml文件中的DatePicker:

<toolbox:DatePicker x:Name="DatePick" Height="Auto" HorizontalAlignment="Center" Margin="0,0,0,0" VerticalAlignment="Top" Width="400" IsEnabled="True"/>

1 个答案:

答案 0 :(得分:1)

使用活动:

使用DatePicker在PopUp中添加一个按钮。单击该按钮时会有一个事件来关闭PopUp

XAML

<toolbox:DatePicker x:Name="DatePick" Height="Auto" HorizontalAlignment="Center" Margin="0,0,0,0" VerticalAlignment="Top" Width="400" IsEnabled="True"/>
<Button Click="DateAcceptedClick"/>

弹出窗口的CodeBehind

public event DateAcceptedButtonClick DateAcceptedButtonEvent;
public delegate void DateAcceptedButtonClick (object sender, RoutedEventArgs e);

private void DateAcceptedClick(object sender, RoutedEventArgs e)
{
     if (DateAcceptedButtonEvent!= null)
         DateAcceptedButtonEvent(sender, e);
}

Popup Parent的CodeBehind

Popup BuyNowScreen;
private void btnShowBuyNow_Click(object sender, RoutedEventArgs e)
{
    BuyNowScreen = new Popup();
    BuyNowScreen.Child = new BuyNowScreen("Buy this application and get rid of the ads!");
    BuyNowScreen.IsOpen = true;
    BuyNowScreen.VerticalOffset = 100;
    BuyNowScreen.HorizontalOffset = 25;
    BuyNowScreen.DateAcceptedButtonEvent += new DateAcceptedButtonClick(PopupDateAcceptedButtonClick)
}

private void PopupDateAcceptedButtonClick(object sender, RoutedEventArgs e)
{
    BuyNowScreen.IsOpen = false;
    //Closed logic
}