繁体   English   中英

Windows Phone中的弹出面板

[英]Popup panel in Windows Phone

我想创建一个控件,其行为类似于Windows Phone的键盘按钮。 当用户点击并按住控件时,控件应展开以显示其他选项。

尽管我通常知道如何实现此控件,但是我不知道如何显示面板,这将超出控件的范围。 如果有一种方法可以在Windows Phone中实现这种效果(应该是-以此方式显示键盘),我该怎么办?

您可以将Popup控件添加到控件中,并通过将Popup的IsOpen属性设置为true来显示它。 弹出窗口可以显示在控件上下文之外。 这是一个非常俗气的UserControl,显示了其“保留中”弹出窗口:

<UserControl x:Class="PhoneApp48.WindowsPhoneControl1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    FontFamily="{StaticResource PhoneFontFamilyNormal}"
    FontSize="{StaticResource PhoneFontSizeNormal}"
    Foreground="{StaticResource PhoneForegroundBrush}"
    d:DesignHeight="480" d:DesignWidth="480"
    Hold="UserControl_Hold">

    <Grid x:Name="LayoutRoot" Background="{StaticResource PhoneChromeBrush}">
        <Rectangle HorizontalAlignment="Stretch" Height="100" Fill="Yellow" />
        <Popup x:Name="myPopup" IsOpen="False">
            <StackPanel Width="{Binding ElementName=LayoutRoot, Path=ActualWidth}" Background="{StaticResource PhoneBackgroundBrush}">
                 <TextBlock TextWrapping="Wrap" Text="Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua." />
                 <Button Click="Button_Click">Close</Button>
            </StackPanel>
        </Popup>
    </Grid>
</UserControl>

码:

private void UserControl_Hold(object sender, System.Windows.Input.GestureEventArgs e)
{
    myPopup.IsOpen = true;
}

private void Button_Click(object sender, RoutedEventArgs e)
{
    myPopup.IsOpen = false;
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM