How to show DatePicker & TimePicker controls over the Popop that contains them?

南笙酒味 提交于 2020-01-02 20:10:18

问题


I'm trying to create a popup with Windows Phone Toolkit DatePicker & TimePicker, with the following 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>

This works, but every time I click either of them, they are rendered under the popup, e.g.

I can't figure out any way to hide the Popup while displaying the DatePicker or TimePicker.

I've tried setting the Z-Index of the controls to be greater than the Popup, as follows:

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

I've also tried hiding the Popup with

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

but this closes the popup and the TimePicker/DatePicker.

Is there any way to view the DatePicker/TimePicker controls on top of the Popup control?


回答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>

Code behind

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;
}


来源:https://stackoverflow.com/questions/20223247/how-to-show-datepicker-timepicker-controls-over-the-popop-that-contains-them

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!