我有一个弹出窗口,但在视觉设计师中它不会拉伸也不会居中。为什么是这样?我怎样才能达到这个效果?
这就是我在可视化树中设置的方式:
<Popup x:Name="namePromptPopup" IsLightDismissEnabled="True" Grid.Row="1" Grid.Column="1">
<Popup.ChildTransitions>
<TransitionCollection>
<PopupThemeTransition/>
</TransitionCollection>
</Popup.ChildTransitions>
<StackPanel>
<Border BorderBrush="White" BorderThickness="5" >
<Border.Background>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="#FF600F0F"/>
<GradientStop Color="#FFB81C1C" Offset="1"/>
</LinearGradientBrush>
</Border.Background>
<StackPanel HorizontalAlignment="Center" VerticalAlignment="Center">
<TextBox Text="Generic Name" FontSize="38" HorizontalAlignment="Center" Width="320" />
<Button Content="Submit" Click="namePromptSubmit" HorizontalAlignment="Center" />
</StackPanel>
</Border>
</StackPanel>
</Popup>
看起来弹出控件似乎没有响应布局。
答案 0 :(得分:1)
我已经检查了网页,感谢this guy,他有一个可以使用的解决方案。
他只是计算窗口宽度/高度,并使用弹出的宽度/高度来给出偏移量。
//Here is where I get a bit tricky. You see namePromptPopup.ActualWidth will show
//the full screen width, and not the actual width of the popup, and namePromptPopup.Width
//will show 0 at this point. So we needed to calculate the actual
//display width. I do this by using a calculation that determines the
//scaling percentage from the height, and then calculates that against my
//original width coding.
namePromptPopup.HorizontalOffset = (currentWindow.Bounds.Width / 2) - (400 / 2);
namePromptPopup.VerticalOffset = (currentWindow.Bounds.Height / 2) - (150 / 2);