2011-04-01 47 views
0

我需要写一个控制,这将是这样的:不能得到正确的标签尺寸

Click Here to se callout

问题是,我不能让标签的实际尺寸重绘我的矩形几何形状。标签的高度总是比真正占据屏幕的空间大得多。我不知道该怎么办。这里是代码:

<Popup x:Class="Controls.Callout" 
     x:ClassModifier="internal" 
     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" > 
    <Grid> 
     <Image> 
      <Image.Source> 
       <DrawingImage> 
        <DrawingImage.Drawing > 
         <GeometryDrawing Brush="Orange" x:Name="geometryDrawing"> 
          <GeometryDrawing.Pen> 
           <Pen Brush="Black" Thickness="2"/> 
          </GeometryDrawing.Pen> 
          <GeometryDrawing.Geometry> 
           <CombinedGeometry GeometryCombineMode="Union"> 
            <CombinedGeometry.Geometry1> 
             <RectangleGeometry x:Name="rectangel" 
                    RadiusX="15" RadiusY="15" 
                     Rect="0,30, 300,100" 
                    /> 
            </CombinedGeometry.Geometry1> 
            <CombinedGeometry.Geometry2> 
             <PathGeometry> 
              <PathFigure StartPoint="30,30" IsClosed="False"> 
               <PolyLineSegment Points="15,0, 90,30"/> 
              </PathFigure> 
             </PathGeometry> 
            </CombinedGeometry.Geometry2> 
           </CombinedGeometry> 
          </GeometryDrawing.Geometry> 
         </GeometryDrawing> 
        </DrawingImage.Drawing> 
       </DrawingImage> 
      </Image.Source> 
     </Image> 
     <Label Padding="5 20" MaxWidth="300" Name="myLabel" FontSize="16" > 
        <!--Content="{Binding}">--> 
       <!--MaxHeight="100" MaxWidth="300">--> 
      <AccessText TextWrapping="Wrap" MaxHeight="50"/> 
     </Label> 
    </Grid> 
</Popup> 

后面的代码:

internal partial class Callout : Popup 
{ 
    public Callout() 
    { 
     InitializeComponent(); 
    } 
    protected override void OnOpened(System.EventArgs e) 
    { 
      rectangel = new RectangleGeometry(new Rect(0,30,300, myLabel.Height/2)); 
    } 
} 

回答

1

为什么不使用带圆角的矩形,一个TextBlock,并在矩形的上面一些形状的网格,使标注“指针“?作为网格,矩形可以自动扩展为TextBlock所需的全尺寸。

例如,您可以创建一个UserControl(或一个完整的模板化控件),并给它一个MaxWidth以便文本换行。然后将该控件放在Canvas中,以便它可以确定它自己的尺寸。

<UserControl MaxWidth="200"> 
    <Grid > 
     <Grid.RowDefinitions> 
      <RowDefinition Height="Auto"/> 
      <RowDefinition Height="Auto"/> 
     </Grid.RowDefinitions> 

     <Rectangle Grid.Row="1" RadiusX="50" RadiusY="50" 
      StrokeThickness="8" Stroke="Gray" /> 
     <!-- Here will be pointer in Grid.Row="0"--> 
     <TextBlock Grid.Row="1" Name="myLabel" Margin="20" Foreground="Black" 
      Text="This is the textblock....." FontSize="20" TextWrapping="Wrap" /> 

    </Grid> 
</UserControl> 
+0

我试图这样: <! - 这里将指针 - > <矩形半径X = “150” 半径= “150”/> 但它不起作用。请你能提供一个你的意思的例子吗? – Seekeer 2011-04-03 15:48:03

+0

谢谢,你帮了我很多! – Seekeer 2011-04-04 15:49:10