我正在尝试创建一个类似于 Windows 8 任务栏中窗口预览选项的弹出窗口。基本上,当我单击或悬停在按钮上时,它会在按钮上方打开一个带有基本信息的弹出窗口。这里是一个示例。
现在,我能够使用以下代码在页面的极左或极右侧打开弹出窗口。
<Frame x:Name="PopUpFrame" HorizontalAlignment="Left" Visibility="Hidden" Height="400" Margin="10,10,0,0" Grid.Row="1" VerticalAlignment="Bottom" Width="400" Source="/BasicApp;component/StandingOrderPopUp.xaml" NavigationUIVisibility="Hidden"/>
我在按钮栏中有三个不同的按钮,因此我无法设置固定的边距。我尝试在代码中设置相同的边距,但是我无法获取绝对位置并将其转换为边距属性。我不确定是否有更好的解决方案。
编辑:
尝试使用弹出窗口,但它不会在按钮单击时打开。
<Popup x:Name="PopUpFrame" Placement="Top" PlacementTarget="{Binding ElementName=StandingOrderButton}" Width="400" Height="400">
<DockPanel Background="#770081a7">
<Canvas DockPanel.Dock="Bottom" x:Name="PopupButtonBar" Height="50" VerticalAlignment="Bottom">
<Button Height="30" Width="125" HorizontalAlignment="Right" VerticalAlignment="Center" Canvas.Top="10" Content="CLOSE" Foreground="White" Background="#ff0081a7" BorderBrush="White" FontFamily="Trebuchet MS" Canvas.Left="10" />
</Canvas>
<Label Margin="5,0,0,0" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" DockPanel.Dock="Top" Content="STANDING ORDERS" Foreground="#ffffffff"></Label>
<Grid DockPanel.Dock="Top">
<Border BorderThickness="2" BorderBrush="#FFff7a00"></Border>
<RichTextBox Margin="2" Foreground="#FF0081a7" FontFamily="Trebuchet MS" IsEnabled="False"/>
</Grid>
</DockPanel>
</Popup>
这里是事件处理程序。
Private Sub StandingOrder_Click(sender As Object, e As RoutedEventArgs)
PopUpFrame.Visibility = Windows.Visibility.Visible
End Sub
编辑:
算了,我太傻了。我设定的不是IsOpen属性,而是可见性。:(
现在它已经完美地工作了,虽然我不得不从另一个页面复制整个设计到这个页面。但至少比没有好。唯一的问题现在是,如果我点击其他东西,我必须编写代码来确保弹出窗口关闭。