2013-04-12 71 views
3

我在WPF 4.5畫布和希望與一個用戶控件,它主要由WPF網格:矩形作爲透明的覆蓋

與標籤網格和半透明的矩形作爲背景疊加它:

<UserControl x:Class="Cwss.Tactical.Navigation.ObjectInfoView" 
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
      xmlns:u="clr-namespace:Cwss.Utils.Converter" 
      xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
      xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
      mc:Ignorable="d" 
      d:DesignHeight="300" 
      d:DesignWidth="300"> 
    <UserControl.Resources> 
    <ResourceDictionary> 
     <ResourceDictionary.MergedDictionaries> 
     <ResourceDictionary Source="/Tactical/Styles/CommonStyle.xaml"></ResourceDictionary> 
     <ResourceDictionary> 
      <Style x:Key="AttrName" 
       TargetType="{x:Type Label}"> 
      <Setter Property="Foreground" 
        Value="White" /> 
      <Setter Property="FontSize" 
        Value="14"></Setter> 
      </Style> 
      <Style x:Key="AttrValue" 
       TargetType="{x:Type Label}"> 
      <Setter Property="Foreground" 
        Value="Yellow" /> 
      <Setter Property="FontSize" 
        Value="14"></Setter> 
      </Style> 
     </ResourceDictionary> 
     </ResourceDictionary.MergedDictionaries> 
    </ResourceDictionary> 
    </UserControl.Resources> 


    <Grid Width="300" 
     Height="200"> 

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

    <Rectangle Panel.ZIndex="-1" 
       Opacity=".5" 
       Width="300" 
       Height="200" 
       Fill="Blue" 
       Stroke="Blue" 
       StrokeThickness="2" 
       RadiusX="8" 
       RadiusY="8"> 
    </Rectangle> 

    <Label Style="{StaticResource AttrName}" 
      Grid.Column="0" 
      Content="Class"></Label> 
    <Label Style="{StaticResource AttrValue}" 
      Grid.Column="1" 
      Name="ObjectKnowledge_Clas" 
      Content="Hi"></Label> 
    <Label Style="{StaticResource AttrName}" 
      Grid.Column="0" 
      Grid.Row="1" 
      Content="Range"></Label> 
    <Label Style="{StaticResource AttrValue}" 
      Grid.Column="1" 
      Grid.Row="1" 
      Content="{Binding ObjectKnowledge.Range, Converter={u:RangetoStringConverter}}"></Label> 
    </Grid> 
</UserControl> 

我奇怪的是,第一個標籤被呈現在矩形Grid with Rectangle

,但所有其他標籤沒有。感謝您讓我知道我在這裏做錯了什麼!

回答

6

嗯,你Rectangle呈現爲在網格與Row=0Column=0的第一個元素(假定爲通過網格默認)

您的矩形切換到類似:

<Rectangle Grid.RowSpan="4" 
      Grid.ColumnSpan="2" 
      Width="300" 
      Height="200" 
      Panel.ZIndex="-1" 
      Fill="Blue" 
      Opacity=".5" 
      RadiusX="8" 
      RadiusY="8" 
      Stroke="Blue" 
      StrokeThickness="2" /> 

現在你看到的其他標籤。

對你那麼

enter image description here

+0

THX還爲工具提示您應該使用Snoop這可能凸顯的問題!......不知道它 – Marco