[英]How to place image in Grid.Row but to keep it responsive WPF
I'm working on a WPF app and I would like to place a user-icon next to a logged in username. 我正在使用WPF应用程序,我想在登录的用户名旁边放置一个用户图标。 I couldn't make it responsive at all and somehow it looks too large on my window. 我根本无法使其具有响应能力,并且以某种方式使其在我的窗口中显得太大。
This is how it looks in Expression Blend (it looks large even in design mode): 这是在Expression Blend中的外观(即使在设计模式下也看起来很大):
Here is my code: 这是我的代码:
[TextBlock Text="User"] [TextBlock Text =“ User”]
[TextBlock Text=" Current username from database " ] [TextBlock Text =“ 数据库 “中的当前用户名 ”
[Rectangle as user icon, Background="Green"] [作为用户图标的矩形,背景=“绿色”]
<TextBlock Grid.Row="3"
Margin="5,5,34,0"
x:Name="lblUser"
VerticalAlignment="Top"
Text="User:"
Foreground="White"
FontSize="13"
d:LayoutOverrides="GridBox" />
<Rectangle Stroke="#83D744"
Grid.Row="3"
RadiusX="0"
RadiusY="0"
Margin="6,24.69,34,10"
d:LayoutOverrides="GridBox">
<Rectangle.Fill>
<SolidColorBrush Color="#5000" />
</Rectangle.Fill>
</Rectangle>
<Image Name="imgExit"
Grid.Row="3"
Source="/MyDesktopApp;component/Images/user-icon.png"
HorizontalAlignment="Left"
MaxHeight="35"
MaxWidth="35"
Margin="15,5,0,10"
VerticalAlignment="Bottom" />
<TextBlock Foreground="White"
Margin="8,40,34,4"
x:Name="lblLoggedInUser"
Grid.Row="3"
FontSize="17"
FontWeight="Bold"
Text=""
TextAlignment="Right" />
This is how it looks when I run the application (on my 22'' monitor) - really bad: 这是我在22英寸显示器上运行应用程序时的外观-真的很糟糕:
And this is how it looks when I run it on a smaller monitor like 17'': 这是我在类似17英寸的较小显示器上运行时的外观:
How could I make it responsive on every size of screen? 如何在各种尺寸的屏幕上做出响应? On 22'' it looks really bad. 在22英寸上看起来真的很糟糕。
You set the Image to an absolute position, I don't think you understood how the Grid works yet. 您将Image设置为绝对位置,我认为您还不了解Grid的工作原理。
Use something like this: 使用这样的东西:
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*"
MinHeight="80" />
</Grid.RowDefinitions>
<TextBlock Grid.Row="0"
Text="User" />
<Border Grid.Row="1"
Padding="8"
BorderBrush="Green"
BorderThickness="2">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"
MinWidth="80" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Image Source="***" Stretch=""Fill/UniformToFill />
<TextBlock Grid.Column="1"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Text="Admin" />
</Grid>
</Border>
</Grid>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.