1

我正在尝试使用 Windows Phone Toolkit DatePicker 和 TimePicker 创建一个弹出窗口,其中包含以下 XAML:

<Popup x:Name="MyPopup">

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

        <StackPanel>

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

        </StackPanel>

    </Border>
</Popup>

这可行,但每次我单击其中任何一个时,它们都会在弹出窗口下呈现,例如

在此处输入图像描述

在显示 DatePicker 或 TimePicker 时,我想不出任何隐藏弹出窗口的方法。

我尝试将控件的 Z-Index 设置为大于 Popup,如下所示:

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。

有没有办法在 Popup 控件之上查看 DatePicker/TimePicker 控件?

4

1 回答 1

1

示例项目。

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;
}
于 2013-11-27T14:26:34.263 回答