我有一个窗口,在其中添加了一个新的UserControl
(带有图像),我只想将控件居中显示在屏幕中间(垂直和水平方向都要)。我只能让垂直居中的部分起作用。 我将从我的CodeBehind交换中的内容,并希望在开始执行幻灯片UI之前显示这个启动屏幕,这意味着内容是从CodeBehind设置的。
我的Window
:
<Window x:Class="GreenWebPlayerWPF.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="512" Width="853" WindowStyle="None" WindowState="Maximized" WindowStartupLocation="CenterScreen">
<DockPanel Width="Auto" Height="Auto" Name="TransitionContainer" Background="Black" Margin="0" LastChildFill="True"></DockPanel>
</Window>
我的UserControl
:
<UserControl x:Class="GreenWebPlayerWPF.FrontPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<DockPanel Background="Black">
<Image Name="image1" Stretch="None" Source="/GreenWebPlayerWPF;component/gw.png" />
</DockPanel>
</UserControl>
请注意,我正在使用最大化/全屏模式。