2012-02-13 4 views
0

У меня есть сетка Silverlight с кучей содержимого в ней (прямоугольники, текстовые блоки и т. Д.), Который представляет контент в комнате. Поскольку он становится довольно сложным, я решил, что мне нужна возможность «масштабирования» в сетке. Я нашел хороший код для этого, но проблема в том, что после масштабирования связанных с сетью ScrollViewer не прокручивает полное расстояние вниз или вправо. Как я могу заставить его обновляться, чтобы я мог прокручивать дно и все вправо?Silverlight ScrollViewer не обновляется после масштабирования

Если это помогает, вот код, чтобы разрешить изменение масштаба моей сетки:

var style = new Style(typeof(Grid)); 
var scale = new ScaleTransform(); 
scale.CenterX = .5; 
scale.CenterY =.5; 
scale.ScaleX = Scale; 
scale.ScaleY = Scale; 
var rs = new Setter(); 
rs.Property = DataGridCell.RenderTransformProperty; 
rs.Value = scale; 
style.Setters.Add(rs); 
OtdrPatchLocationGrid.Style = style; 

и вот XAML, который показывает сетку и зрителя прокрутки

<ScrollViewer Name="scViewer" Grid.Row="1" Visibility="Visible" VerticalScrollBarVisibility="Visible" HorizontalScrollBarVisibility="Visible"> 
     <Grid x:Name="OtdrPatchLocationGrid" MinHeight="350" VerticalAlignment="Stretch" Background="Yellow" Grid.Row="1" Grid.Column="0" Margin="0" MouseDown="OtdrRackViewer_MouseDown"> 

     </Grid> 
    </ScrollViewer> 

ответ

0

Я работаю над тот же вопрос сейчас,

ScrollViewer влияет только на изменение ширины или высоты, , поэтому для устранения проблемы вам необходимо выполнить следующие действия:

предположим, что мы получили сетку или холст с именем (ZoomCanvas)

в коде позади:

double initialCanvasHeight; 
double initialCanvasWidth; 
public void MainPage() //As the Constructor 
{ 
initialCanvasHeight = ZoomCanvas.Height; 
initialCanvasWidth = ZoomCanvas.Width; 
} 

ZoomCanvas_MouseWheel(object sender, MouseWheelEventArgs e) 
{ 

/*Assuming you have the scaling code here and the object CanvasScale is used to scale the canvas*/ 

foreach (var node in ZoomCanvas) 
      { 
       var nodeTop = Canvas.GetTop(node); 
       var nodeLeft = Canvas.GetLeft(node); 
       if(mostTopValue < nodeTop) 
        mostTopValue = nodeTop; 
       if(mostLeftValue < nodeLeft) 
        mostLeftValue = nodeLeft; 
       var desiredHeight = (mostTopValue + NodeHeight)*canvasScale.ScaleY; 
       var desiredWidth = (mostLeftValue + NodeWidth) * canvasScale.ScaleX; 
       if (desiredHeight > canvasInitialHeight) 
       { 
        while (heightToIncrease < desiredHeight) 
         heightToIncrease += 10; 
        ZoomCanvas.Height = heightToIncrease; 
       } 
       else 
        while (ZoomCanvas.Height > canvasInitialHeight) 
         ZoomCanvas.Height -= 10; 
       if (desiredWidth > canvasInitialWidth) 
       { 
        while (widthToIncrease < desiredWidth) 
         widthToIncrease += 10; 
        ZoomCanvas.Width = widthToIncrease; 
       } 
       else while (ZoomCanvas.Height > canvasInitialHeight) 
        ZoomCanvas.Width -= 10; 
      } 
      scrollViewer.UpdateLayout(); 
}