[英]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.