我正在研究一个C#WPF应用程序,并且当我最大化主窗口时,我正在尝试将image1控件设置为dock fill,但是发生的事情是image1不会扩展以填充窗口。我不知道如何解决这个问题?下面是使用的XAML脚本。
<Grid Name="layoutGrid" Margin="10 0 10 0" Width="1847">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="342*" />
<ColumnDefinition Width="142*" />
<ColumnDefinition Width="1363*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<DockPanel Margin="0,0,0,20" Grid.ColumnSpan="3">
<Image DockPanel.Dock="Left" Source="Images\Logo.png" Stretch="None" Margin="0 10 0 5"/>
<TextBlock DockPanel.Dock="Right" VerticalAlignment="Bottom" Foreground="{StaticResource MediumGreyBrush}" FontFamily="Segoe UI" FontSize="18">Basics</TextBlock>
<Image Grid.Column="1" Source="Images\Status.png" Stretch="None" HorizontalAlignment="Center" Margin="0 0 0 5"/>
</DockPanel>
<Viewbox Grid.Row="1" Stretch="Uniform" HorizontalAlignment="Left" Grid.ColumnSpan="3">
<Image Name="Image1" Width="640" Height="480" Margin="0,0,0,0" RenderOptions.BitmapScalingMode="HighQuality" Visibility="Visible" />
</Viewbox>
<Viewbox Grid.Row="1" Stretch="Uniform" HorizontalAlignment="Left" Grid.ColumnSpan="3">
<Image Name="Image3" Width="640" Height="480" Margin="0,0,0,0" RenderOptions.BitmapScalingMode="HighQuality" Visibility="Hidden" Stretch="None" />
</Viewbox>
<Viewbox Grid.Row="1" Stretch="Uniform" HorizontalAlignment="Right" Grid.Column="2">
<Image Name="Image2" Width="640" Height="480" Margin="0,0,0,0" RenderOptions.BitmapScalingMode="HighQuality" Visibility="Hidden" />
</Viewbox>
</Grid>
这是在最大化屏幕之前,这是在最大化之后
答案 0 :(得分:1)
在这里,问题是ViewBox中的Stretch模式。控件占据了所需的空间,但是视图框限制它以避免裁剪。填充将利用所有空间,同时裁剪图像的某些部分
<Viewbox Grid.Row="1" Stretch="Fill" HorizontalAlignment="Left" Grid.ColumnSpan="3">
<Image Name="Image1" Width="640" Height="480" Margin="0,0,0,0" RenderOptions.BitmapScalingMode="HighQuality" Visibility="Visible" />
</Viewbox>
<Viewbox Grid.Row="1" Stretch="Fill" HorizontalAlignment="Left" Grid.ColumnSpan="3">
<Image Name="Image3" Width="640" Height="480" Margin="0,0,0,0" RenderOptions.BitmapScalingMode="HighQuality" Visibility="Hidden" Stretch="None" />
</Viewbox>
<Viewbox Grid.Row="1" Stretch="Fill" HorizontalAlignment="Right" Grid.Column="2">
<Image Name="Image2" Width="640" Height="480" Margin="0,0,0,0" RenderOptions.BitmapScalingMode="HighQuality" Visibility="Hidden" />
</Viewbox>