2014-04-30 49 views
0

我有問題要得到電網 的值平移X,我可以通過複合設置在網格中的值轉換平移X XAML

CompositeTransform dd = new CompositeTransform(); 
    CompositeTransform dd = new CompositeTransform(); 

     dd.TranslateX = Convert.ToInt32(tabl.x); 
     dd.TranslateY = Convert.ToInt32(tabl.y); 
     dd.Rotation = Convert.ToInt32(tabl.r); 

     grid.RenderTransform = dd; 

,但我不能把價值

回答

1

您可以隨時通過Grid的RenderTransform屬性訪問現有CompositeTransform。因此,你應該設置CompositeTransform一次,最好在XAML:

<Grid x:Name="grid"> 
    <Grid.RenderTransform> 
     <CompositeTransform/> 
    </Grid.RenderTransform> 
</Grid> 

現在你可以這樣寫代碼:

var transform = (CompositeTransform)grid.RenderTransform; 

// set values 
transform.TranslateX = tabl.x; 
transform.TranslateY = tabl.y; 
transform.Rotation = tabl.r; 

// get values 
var x = transform.TranslateX; 
var y = transform.TranslateY; 
var r transform.Rotation; 
0

你可以得到電網這樣的平移X值:

double translateX = (grid.RenderTransform as CompositeTransform).TranslateX;