1

我正在尝试使用给定的布局创建一个窗口,我很好奇最好的方法。我已将窗口背景设置为较浅颜色的平铺图像。然后我想我会添加一个带有五列和一行的统一网格,其中第 5 列具有“橙色”略微透明的背景。然后,我将添加另一个具有 5 行和 1 列的统一网格,其中第 2 行和第 3 行具有相同的“橙色”颜色设置。最终,我将在左上角添加公司徽标,并在“橙色”的水平带中添加一些文本。我的方法似乎不起作用:-(我自己正在研究的任何指导将不胜感激。例子

4

2 回答 2

2

这对我很有效:

<Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:sys="clr-namespace:System;assembly=mscorlib"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="5*"/>
            <ColumnDefinition Width="*"/>
        </Grid.ColumnDefinitions>
        <Grid Grid.Row="0" Grid.Column="0" Background="Yellow">
            <Image Source="http://www.google.com/images/srpr/logo3w.png"
                   HorizontalAlignment="Left"/>
        </Grid>
        <Grid Grid.Row="0" Grid.Column="1" Background="Orange"/>
        <Grid Grid.Row="1" Grid.Column="0" Background="Orange"/>
        <Grid Grid.Row="1" Grid.Column="1" Background="Red"/>
        <Grid Grid.Row="2" Grid.Column="0" Background="Yellow"/>
        <Grid Grid.Row="2" Grid.Column="1" Background="Orange"/>
        <TextBlock Grid.Row="1" Grid.ColumnSpan="2" Grid.Column="0">
            I am nice text spanning the whole row! Look, here's a lot
            of me in the cell.
        </TextBlock>
    </Grid>
</Page>

如果你坚持半透明条纹,你可以做类似的东西

<Grid Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="1"
      Background="Orange" Opacity="0.5"/>

或者

<Grid Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="1" Background="#80FF7F00"/>

(包括颜色的不透明度)等。

例如,试试这个(你需要调整颜色):

<Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:sys="clr-namespace:System;assembly=mscorlib"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="*"/>
            <RowDefinition Height="*"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="5*"/>
            <ColumnDefinition Width="*"/>
        </Grid.ColumnDefinitions>
        <Grid Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="2"
              Background="Yellow" Opacity="0.5"/>
        <Grid Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2"
              Background="Orange" Opacity="0.5"/>
        <Grid Grid.Row="2" Grid.Column="0" Grid.ColumnSpan="2"
              Background="Yellow" Opacity="0.5"/>
        <Grid Grid.Row="0" Grid.Column="0" Grid.RowSpan="3"
              Background="Yellow" Opacity="0.5"/>
        <Grid Grid.Row="0" Grid.Column="1" Grid.RowSpan="3"
              Background="Orange" Opacity="0.5"/>
        <Image Grid.Row="0" Grid.Column="0"
               Source="http://www.google.com/images/srpr/logo3w.png"
               HorizontalAlignment="Left"/>
        <TextBlock Grid.Row="1" Grid.ColumnSpan="2" Grid.Column="0">
            I am nice text spanning the whole row! Look, here's a lot
            of me in the cell.
        </TextBlock>
    </Grid>
</Page>
于 2012-07-01T18:26:51.167 回答
1

简短的回答就是使用网格并将单元格的背景颜色设置为我选择的具有轻微透明度的颜色。然后我可以将相交的单元格设置为较深的颜色,或者将标签添加到具有相同背景和透明度的相交单元格。感谢大家的帮助。在过去的一个小时里,我学到了很多关于 xaml 和 WPF 的知识。

于 2012-07-01T20:28:23.257 回答