2013-09-23 83 views
0

無法理解爲什麼Translatetransform綁定不起作用。我有3個滑塊 - 一個用於縮放,另外兩個用於x和y轉換(我的圓圈代碼爲Canvas的子元素)。TranslateTransform與滑塊綁定不起作用

我使用下面的XAML:

<Window x:Class="Visualizer.MainWindow" 
     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
     Title="MainWindow" WindowState="Maximized" WindowStartupLocation="CenterScreen" ResizeMode="NoResize"> 
    <Canvas HorizontalAlignment="Stretch" Margin="0,0,0,0" VerticalAlignment="Stretch" Name="MainCanvas" > 
     <Canvas HorizontalAlignment="Stretch" Margin="0,0,0,0" VerticalAlignment="Stretch" Name="OperatorsCanvas" > 
      <ContentControl x:Name="OperatorsContent"/> 
      <Canvas.LayoutTransform> 
       <TransformGroup> 
        <ScaleTransform 
        CenterX="0" 
        CenterY="0" 
        ScaleX="{Binding ElementName=ScaleSlider,Path=Value}" 
        ScaleY="{Binding ElementName=ScaleSlider,Path=Value}" 
        /> 
        <TranslateTransform X="{Binding ElementName=TranslateXSlider,Path=Value}" Y="{Binding ElementName=TranslateYSlider,Path=Value}" /> 
       </TransformGroup> 
      </Canvas.LayoutTransform> 
     </Canvas> 
     <Slider Canvas.Right="5" Width="154" Canvas.Top="5" HorizontalAlignment="Right" Name="ScaleSlider" ToolTip="Determines the UI scale factor." 
        Value="1" Minimum="0.1" Maximum="4"/> 
     <Slider Canvas.Bottom="0" Width="762" HorizontalAlignment="Stretch" Name="TranslateXSlider" Value="0" Minimum="-20" Maximum="20"/> 
     <Slider Canvas.Right="0" Canvas.Top="282" Width="423" RenderTransformOrigin="0.494,0.455" Height="16" Name="TranslateYSlider" Value="0" Minimum="-20" Maximum="20" > 
      <Slider.RenderTransform> 
       <TransformGroup> 
        <ScaleTransform/> 
        <SkewTransform/> 
        <RotateTransform Angle="90"/> 
        <TranslateTransform/> 
       </TransformGroup> 
      </Slider.RenderTransform> 
     </Slider> 
    </Canvas> 
</Window> 

縮放的作品,但改造不會。

回答

4

LayoutTransform中的翻譯將被忽略,正如在MSDN上的LayoutTransform文檔中的備註部分所述。你將不得不通過RenderTransform以取代LayoutTransform,使其工作:

<Canvas ...> 
    <Canvas.RenderTransform> 
     <TransformGroup> 
      <ScaleTransform 
       ScaleX="{Binding ElementName=ScaleSlider,Path=Value}" 
       ScaleY="{Binding ElementName=ScaleSlider,Path=Value}"/> 
      <TranslateTransform 
       X="{Binding ElementName=TranslateXSlider,Path=Value}" 
       Y="{Binding ElementName=TranslateYSlider,Path=Value}"/> 
     </TransformGroup> 
    </Canvas.RenderTransform> 
    ... 
</Canvas> 

也請注意,滑塊有一個Orientation屬性。因此,不需要在那裏應用變換。