2013-08-01 187 views
1

我有一個Grid,通過滑塊縮放/縮放ScaleTransform。在運行時,許多UIElements被添加到這個Grid按比例縮放回WPF

我想顯示一些工具提示,但沒有縮放!我應該怎麼做?

例如:Grid有scaleX和scaleY 2,所以我設置了新的ScaleTransform(0.5,0.5),但沒有幫助。似乎最相似的值是0.740 ..爲什麼? 即使Grid的LayoutTransform.Inverse設置爲縮放值0.5。

XAML:

<ScrollViewer HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto" Height="Auto" Width="Auto" Name="graphScrollViewer" ScrollChanged="graphScrollViewer_ScrollChanged"> 
<Grid Margin="0,0,0,0" Name="graphGrid" Width="Auto" Height="Auto" ScrollViewer.IsDeferredScrollingEnabled="True" MouseLeftButtonDown="graphGrid_MouseLeftButtonDown" MouseLeftButtonUp="graphGrid_MouseLeftButtonUp" MouseMove="graphGrid_MouseMove"> 
    <Grid.LayoutTransform> 
     <ScaleTransform ScaleX="{Binding ElementName=sldZoom, Path=Value}" ScaleY="{Binding ElementName=sldZoom, Path=Value}" /> 
    </Grid.LayoutTransform> 
</Grid> 
</ScrollViewer> 

<Slider Minimum="0.1" Maximum="20" Value="1" x:Name="sldZoom" Panel.ZIndex="10" Orientation="Horizontal" VerticalAlignment="Bottom" HorizontalAlignment="Right" Margin="0,0,20,20" Height="23" Width="100" ValueChanged="sldZoom_ValueChanged"/> 

代碼隱藏: (矩形(MouseEnter事件)的方法動態添加到網格)

private void rect_MouseEnter(object sender, MouseEventArgs e) 
{ 
    RectToolTip = new TextBlock(); 
    RectToolTip.HorizontalAlignment = HorizontalAlignment.Left; 
    RectToolTip.VerticalAlignment = VerticalAlignment.Top; 
    RectToolTip.TextAlignment = TextAlignment.Center; 
    RectToolTip.Height = this.HeaderTwoHeight + 1; 
    RectToolTip.Text = " " + (RectsTasks[(sender as Rectangle)]).Info + " "; 
    RectToolTip.Background = this.ToolTipBackground; 
    RectToolTip.Foreground = this.ToolTipFontColor; 

    RectToolTipBorder = new Border(); 
    RectToolTipBorder.Child = RectToolTip; 
    RectToolTipBorder.BorderThickness = new Thickness(this.ToolTipBorderThickness); 
    RectToolTipBorder.BorderBrush = this.ToolTipBorderColor; 
    RectToolTipBorder.Margin = new Thickness(e.GetPosition((graphGrid)).X + 10,  e.GetPosition((graphGrid)).Y + 10, 0, 0); 
    RectToolTipBorder.VerticalAlignment = System.Windows.VerticalAlignment.Top; 
    RectToolTipBorder.HorizontalAlignment = System.Windows.HorizontalAlignment.Left; 

    graphGrid.Children.Add(RectToolTipBorder); 

    RectToolTipBorder.LayoutTransform = RectToolTip.LayoutTransform = new ScaleTransform(????);   
    Grid.SetZIndex(RectToolTip, 20); 
    Grid.SetZIndex(RectToolTipBorder, 20); 
} 

回答

3

您需要分配逆變換的子元素,以便孩子保持完好。

RectToolTipBorder.LayoutTransform = graphGrid.LayoutTransform.Inverse as Transform; 
+0

嗯,只給這個元素設置了轉換。謝謝! – user2640669