简体   繁体   English

如何将图像添加到 WPF C# XAML 应用程序中的列

[英]How to add images to columns in WPF C# XAML application

I am new to C# and WPF development, and I am working on a program that encodes and decodes bitmaps.我是 C# 和 WPF 开发的新手,我正在开发一个编码和解码位图的程序。 I have the following XAML code and its expected output:我有以下 XAML 代码及其预期的 output:

<Page x:Class="Thompson_EncodeDecode.BeforeDecoding"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
  xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
  xmlns:local="clr-namespace:Thompson_EncodeDecode"
  mc:Ignorable="d" 
  d:DesignHeight="450" d:DesignWidth="800"
  Title="BeforeDecoding">

<Grid Margin="10,0,10,10">
    <Grid.ColumnDefinitions>
        <ColumnDefinition />
        <ColumnDefinition />
    </Grid.ColumnDefinitions>
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto"/>
        <RowDefinition Height="Auto"/>
    </Grid.RowDefinitions>
    <Border Grid.Column="0" Height="35" Padding="5" Background="White">
        <Label VerticalAlignment="Center" Foreground="Black">Before Encoding</Label>
    </Border>
    <Border Grid.Column="1" Height="35" Padding="5" Background="White">
        <Label VerticalAlignment="Center" Foreground="Black"> After Encoding</Label>
    </Border>
</Grid>

到目前为止的预期产出

What I am trying to do is add an image onto both columns of the grid so that I can show that the images are the same, but also below that show what the encoded and decoded message within the bitmap is to show that the encoding is actually working.我想要做的是在网格的两列上添加一个图像,以便我可以显示图像是相同的,但也在下面显示 bitmap 中的编码和解码消息是为了显示编码实际上是在职的。 I am unsure how to add an image to the column without either making the image the background for the grid, and also maintaining the Grid integrity.我不确定如何在不将图像作为网格背景的情况下将图像添加到列中,并且还要保持网格的完整性。

Also some extra pointers on how to have the input data shown on the bottom right of the grid column would be helpful too.此外,关于如何在网格列的右下角显示输入数据的一些额外指示也会有所帮助。 Most of the Googling I have been doing regarding this particular program has confused me, and I am wondering if there is a standard way of approaching it.我对这个特定程序所做的大部分谷歌搜索都让我感到困惑,我想知道是否有一种标准的方法来处理它。

在此处输入图像描述

You can achieve this in many ways, one of the way is as follows您可以通过多种方式实现这一点,其中一种方式如下

<Grid Background="Gray">
    <Grid.ColumnDefinitions>
        <ColumnDefinition/>
        <ColumnDefinition/>
    </Grid.ColumnDefinitions>

    <!-- U can move this duplicate code into an usercontrol to reuse-->
    <Grid Grid.Column="0">
        <Grid.RowDefinitions>
            <!--Header-->
            <RowDefinition Height="1*"/>
            <!--Body-->
            <RowDefinition Height="8*"/>
            <!--Footer-->
            <RowDefinition Height="1*"/>
        </Grid.RowDefinitions>

        <Label Content="Header" Grid.Row="0"/>
        <Image Grid.Row="1"/>
        <Label Content="footer" Grid.Row="2" HorizontalContentAlignment="Right"/>


    </Grid>

    <Grid Grid.Column="1">
        <Grid.RowDefinitions>
            <!--Header-->
            <RowDefinition Height="1*"/>
            <!--Body-->
            <RowDefinition Height="8*"/>
            <!--Footer-->
            <RowDefinition Height="1*"/>
        </Grid.RowDefinitions>

        <Label Content="Header" Grid.Row="0"/>
        <Image Grid.Row="1"/>
        <Label Content="footer" Grid.Row="2" HorizontalContentAlignment="Right"/>

    </Grid>

</Grid>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM