为什么启动后的应用程序看起来与设计师不同?

发布于 2025-01-24 04:02:53 字数 2008 浏览 0 评论 0原文

我有一个问题。我是WPF的新手,我发生了一件奇怪的事情。在设计师中,一切看起来都不错,但是一旦我启动应用程序,就可以切断“(Via.photo)”,看起来很糟糕。是否可以响应应用程序?

”

我的XAML代码:

<TabItem Header="TabItem" 
                 Visibility="Hidden" 
                 x:Name="Home_Page" 
                 Background="{x:Null}" 
                 BorderBrush="{x:Null}" Height="Auto"
                 Width="Auto"
                 >

            <Border 
                Background="Black"
                HorizontalAlignment="Center"
                VerticalAlignment="Center" 
                Width="1340" 
                Height="1100"
                CornerRadius="20"
                >
                <Border
                    Background="White" 
                    CornerRadius="20"
                    Height="700"
                    Width="500"
                    Margin="0" HorizontalAlignment="Center" VerticalAlignment="Center"
                   
                    >
                    <Grid 
                        
                        >
                        <TextBlock
                            Text="Welcome"
                            Width="200"
                            Height="200"
                            Foreground="Black"
                            FontSize="50" FontFamily="/Peel_App;component/Fonts/#Kashima Brush Demo"
                            
                            >

                        </TextBlock>

                    </Grid>

                </Border>

            </Border>

        </TabItem>

在我编辑的应用程序之后:

I have a little question. I'm new to WPF and a strange thing happened to me. In the designer everything looks fine, but as soon as I start the application, a piece ,,cuts off"(via.photo) and it looks pretty bad. Could it be that the application is not responsive?
How does it look like after starting

How does it look like in XAML designer

My XAML code:

<TabItem Header="TabItem" 
                 Visibility="Hidden" 
                 x:Name="Home_Page" 
                 Background="{x:Null}" 
                 BorderBrush="{x:Null}" Height="Auto"
                 Width="Auto"
                 >

            <Border 
                Background="Black"
                HorizontalAlignment="Center"
                VerticalAlignment="Center" 
                Width="1340" 
                Height="1100"
                CornerRadius="20"
                >
                <Border
                    Background="White" 
                    CornerRadius="20"
                    Height="700"
                    Width="500"
                    Margin="0" HorizontalAlignment="Center" VerticalAlignment="Center"
                   
                    >
                    <Grid 
                        
                        >
                        <TextBlock
                            Text="Welcome"
                            Width="200"
                            Height="200"
                            Foreground="Black"
                            FontSize="50" FontFamily="/Peel_App;component/Fonts/#Kashima Brush Demo"
                            
                            >

                        </TextBlock>

                    </Grid>

                </Border>

            </Border>

        </TabItem>

After what I edited app:note that I set Height and Width of Window also to auto and every Grid as well

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

因为看清所以看轻 2025-01-31 04:02:53

您的代码有一些问题:

  1. 您正在硬编码保证金值以定位控件。相反,您应该使用适当的面板(dockpanelwrappanelgrid)。使用保证金属性设置保证金而不是位置。
  2. 使用horizo​​ntalAlignment垂直安装属性将元素定位,因此您的UI将更加响应和用户友好。
  3. 为了查看,您的窗口及其内容的外观 - 尝试设置d:designHeghtd:designWidth窗口上的属性。尝试使用Google如何使用它们。

最后,您的代码应该如下:

<TabItem Header="TabItem"
         Visibility="Hidden"
         x:Name="Home_Page"
         Background="{x:Null}"
         BorderBrush="{x:Null}"> <!-- Properties order is a bit confusing, it is better to order them by priority, or just alphabetically. -->
    <Border Background="Black">
        <Border Background="White"
                CornerRadius="20"
                Margin="0,0,93,118"> <!-- Should it have such values? Maybe just somenthing like Margin="0 0 90 120"? -->
            <Grid>
                <TextBlock Text="Welcome"
                           Foreground="Black"
                           FontSize="50" 
                           FontFamily="/Peel_App;component/Fonts/#Kashima Brush Demo"/>
            </Grid>
        </Border>
    </Border>
</TabItem>

Your code has a few issues:

  1. You're hardcoding the Margin values to position your controls. Instead, you should use proper panels (DockPanel, WrapPanel, and Grid). Use Margin property to set margin, not a position.
  2. Use HorizontalAlignment and VerticalAlignment properties to position your elements, thus your UI would be more responsive and user-friendly.
  3. To be able to view, how your window and its content would look like - try to set d:DesignHeght and d:DesignWidth properties on a window. Try to Google how to use them.

In the end, your code should look like following:

<TabItem Header="TabItem"
         Visibility="Hidden"
         x:Name="Home_Page"
         Background="{x:Null}"
         BorderBrush="{x:Null}"> <!-- Properties order is a bit confusing, it is better to order them by priority, or just alphabetically. -->
    <Border Background="Black">
        <Border Background="White"
                CornerRadius="20"
                Margin="0,0,93,118"> <!-- Should it have such values? Maybe just somenthing like Margin="0 0 90 120"? -->
            <Grid>
                <TextBlock Text="Welcome"
                           Foreground="Black"
                           FontSize="50" 
                           FontFamily="/Peel_App;component/Fonts/#Kashima Brush Demo"/>
            </Grid>
        </Border>
    </Border>
</TabItem>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文