0

问题是图像没有固定在屏幕的右侧,所以当我调整屏幕大小时,图像会离开屏幕,例如:

在此处输入图像描述

在该示例中,我们应该看到完整手机的图像。

我定义了以下网格布局:

<Grid Background="White" >
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="23" />
        <ColumnDefinition Width="166" />
        <ColumnDefinition Width="473" />
        <ColumnDefinition Width="330" />
    </Grid.ColumnDefinitions>
    <Grid.RowDefinitions>
        <RowDefinition Height="50" />
        <RowDefinition Height="35" />
        <RowDefinition Height="35" />
        <RowDefinition Height="35" />
        <RowDefinition Height="50" />
        <RowDefinition Height="*" />
    </Grid.RowDefinitions>

    <!-- some irrelevant stuff removed -->

    <Canvas Grid.Column="3" HorizontalAlignment="Right" >

        <Image HorizontalAlignment="Left" Name="imgLogo" Stretch="Uniform" VerticalAlignment="Center" Width="45" Height="45" Margin="30,135,0,0" Canvas.ZIndex="99" Canvas.Left="0" Canvas.Top="-7" />
        <Image Source="/Resources/Images/MobileBrandingSample.png" Height="634" Width="316" HorizontalAlignment="Left" Margin="0,14,0,0" Name="imgPhone" Stretch="Uniform" VerticalAlignment="Top"  />
        <Label Canvas.Left="80" Canvas.Top="127" Content="" Height="20" Name="lblCompanyName" Width="169" FontSize="15" Padding="0,0,0,0" />

        <Label Canvas.Left="80" Canvas.Top="150" Height="20" Name="lblPhoneNumber" Width="160" FontSize="12" Padding="0,0,0,0">
            <TextBlock Name="tbPhoneNumberLabel" Text="" TextDecorations="Underline" Foreground="#35B6E5" Width="160"></TextBlock>
        </Label>
    </Canvas>

</Grid>

有了这个,imgPhone它是右对齐的,但是当我调整窗口大小时,它imgPhone会离开屏幕。imgPhone无论窗口大小如何调整,我都需要保持停靠在屏幕右侧吗?

4

2 回答 2

0

抛弃画布,使用带有网格的 Dockpanel,将所有内容停靠在正确的位置,网格中的绝对大小将使您希望它们相对于其他所有内容保持在您想要的位置。

于 2013-10-18T10:24:41.827 回答
0

我试过这个......并得到了一个解决方案......也许不完全是你想要的,但我认为你可以完成所需的一些调整。

<Grid Background="White" >
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="Auto"></ColumnDefinition>
        <ColumnDefinition Width="Auto"></ColumnDefinition>
        <ColumnDefinition Width="*"></ColumnDefinition>
    </Grid.ColumnDefinitions>
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto"></RowDefinition>
        <RowDefinition Height="Auto"></RowDefinition>
        <RowDefinition Height="Auto"></RowDefinition>
        <RowDefinition Height="*"></RowDefinition>
    </Grid.RowDefinitions>

    <TextBlock Grid.Row="0" Grid.Column="0" Text="company name"></TextBlock>
    <TextBlock Grid.Row="1" Grid.Column="0" Text="Phone number"></TextBlock>
    <TextBlock Grid.Row="2" Grid.Column="0" Text="Logo name"></TextBlock>
    <Button  Grid.Row="3" Grid.Column="0" Content="Upgrade branding"></Button>

    <TextBox Grid.Row="0" Grid.Column="1"></TextBox>
    <TextBox Grid.Row="1" Grid.Column="1"></TextBox>
    <Button Grid.Row="2" Grid.Column="1" Content="Load logo"></Button>

    <Image Grid.Column="2" Grid.RowSpan="4" HorizontalAlignment="Right" Source="C:\Users\somonteiro\Desktop\Montagens\somonteiro.jpg"></Image>

</Grid>
于 2013-10-18T10:26:01.447 回答