我有一個小問題。我是 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>
在我編輯應用程式之后:
uj5u.com熱心網友回復:
您的代碼有幾個問題:
- 您正在對
Margin值進行硬編碼以定位控制元件。相反,您應該使用適當的面板(DockPanel、WrapPanel和Grid)。使用Margin屬性來設定邊距,而不是位置。 - 使用
HorizontalAlignment和VerticalAlignment屬性來定位您的元素,因此您的 UI 將更具回應性和用戶友好性。 - 為了能夠查看您的視窗及其內容的外觀 - 嘗試在視窗上設定
d:DesignHeght和d:DesignWidth屬性。嘗試谷歌如何使用它們。
最后,您的代碼應如下所示:
<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>
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/465027.html
上一篇:解決idea中每次創建專案都要重復配置maven,來看全網僅需幾步全域配置
下一篇:訊息佇列與快遞柜之間的奇妙關系
