【问题标题】:Stretch and center a popup in Metro apps在 Metro 应用程序中拉伸和居中弹出窗口
【发布时间】:2023-03-12 03:56:03
【问题描述】:

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

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

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

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

【问题讨论】:

    标签: c# visual-studio-2012 popup microsoft-metro


    【解决方案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);
    

    Reference again

    【讨论】:

    • 谢谢,我担心我必须以编程方式进行。我想只是脾气暴躁地坐在那里不会做任何事情,但如果内在的布局属性能够工作,那仍然会很好。无论如何,谢谢!
    • 是否可以在不为弹出控件分配高度和宽度并获取其高度和宽度的情况下执行此操作?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-10
    • 2014-03-03
    • 1970-01-01
    • 2015-05-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多