1

我有一个通过滑块Grid缩放/缩放的。ScaleTransform在运行时,许多 UIElements 被添加到这个Grid.

我想显示一些工具提示,但没有缩放!我该怎么做?

例如:Grid有 scaleX 和 scaleY 2,所以我设置了 new ScaleTransform(0.5, 0.5),但没有帮助。似乎最相似的值是 0.740.. 为什么?EvenGrid的 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);
}
4

1 回答 1

6

您需要将逆变换分配给子元素,以便子元素保持不变。

RectToolTipBorder.LayoutTransform = graphGrid.LayoutTransform.Inverse as Transform;
于 2013-08-01T05:55:40.680 回答