1

我有一个弹出窗口,但在视觉设计器中它既不拉伸也不居中。为什么是这样?我怎样才能达到这个效果?

这就是我在可视化树中设置它的方式:

    <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>

似乎弹出控件根本不响应布局。

4

1 回答 1

1

我检查了网络,感谢这个人,他有一个你可以使用的解决方案。

他只是计算窗口宽度/高度并使用弹出窗口宽度/高度来给出偏移量。

//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);

再次参考

于 2013-02-15T14:37:58.110 回答