J'ai une fenêtre où j'ajoute un nouveau UserControl
(avec une image), je veux simplement centrer le contrôle au milieu de l'écran (verticalement et horizontalement). Je peux seulement faire fonctionner le vertical. Je vais échanger du contenu dans le DockPanel
de mon CodeBehind et je veux montrer cet écran de démarrage avant de commencer à faire mon diaporama, cela signifie que le contenu est défini à partir du CodeBehind.Centrer un contrôle WPF
Mon 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>
Mon 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>
S'il vous plaît noter que je suis en utilisant l'écran maximisé/plein.
Thx un groupe, cela fonctionne :-) – H4mm3rHead
Cela ne fonctionne pas sur Windows RT –
Le cadre fondé sur XAML qui est utilisé pour écrire sur App Store RT n'est pas WPF. Si quelque chose, c'est plus d'un dérivé de Silverlight. –