我有我的标签
<Label Content="$500" Height="113" HorizontalAlignment="Left" Margin="12,21,0,0"
Name="label1" VerticalAlignment="Top" BorderBrush="Black" AllowDrop="False"
Panel.ZIndex="1" Width="350" Foreground="#FFEFEFEF" FontFamily="Arial"
FontSize="100">
我试过这个:
label1.Width = System.Windows.SystemParameters.PrimaryScreenWidth;
但它不起作用。如何让标签的宽度为PrimaryScreenWidth
?
以下是我的完整代码:
<Window x:Class="Game.Player1Screen"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Player1Screen" Height="300" Width="300">
<Grid>
<Label Content="$500" Height="113" HorizontalAlignment="Left" Margin="12,21,0,0" Name="label1" VerticalAlignment="Top" BorderBrush="Black" AllowDrop="False" Panel.ZIndex="1" Width="{x:Static SystemParameters.PrimaryScreenWidth}" Foreground="#FFEFEFEF" FontFamily="Arial" FontSize="100">
<Label.LayoutTransform>
<RotateTransform Angle="270"/>
</Label.LayoutTransform>
</Label>
<ProgressBar Name="ProgressBarTimer" Panel.ZIndex="0" Orientation="Horizontal" Foreground="Blue" Background="Black" MouseLeftButtonDown="ProgressBarTimer_MouseLeftButtonDown"
Value="0" HorizontalAlignment="Left" Maximum="100" VerticalAlignment="Top" Height="{x:Static SystemParameters.PrimaryScreenHeight}" Width="{x:Static SystemParameters.PrimaryScreenWidth}">
</ProgressBar>
</Grid>
</Window>
答案 0 :(得分:0)
你做了什么会有用,或者你可以在XAML中设置它:
<Label Width="{x:Static SystemParameters.PrimaryScreenWidth}" />
但是,标签的宽度(ActualWidth
)将受其所在容器的约束 - 无论Width
设置为何种。