Saturday, December 8, 2012

take image of full datagrid

take image of full datagrid

I have:

<Grid>  <Grid.RowDefinitions>    <RowDefinition></RowDefinition>  </Grid.RowDefinitions>   <sdk:DataGrid Grid.Row="0" ...>  ...  </sdk:DataGrid>  </Grid> 

Note there is no Height="Auto" in row definition so that datagrid takes all height. I'm trying to make a picture of full datagrid (include invisible space that needs scrolling). I tried:

ImageExtensions.ToImage(myDataGrid); 

also

var writeableBitmap = new WriteableBitmap(pixelWidth, pixelHeight); 

where pixelHeight was obtained either using SizeChanged event or DesiredSize property.

All in vain. Height was always the height of screen. If I used auto="height" in row definition then it would work, but datagrid wouldn't take all space / or no scroller when it's too large.

Anyone managed to get it work?

Answers & Comments...

Answer: 1

A workaround:

GridLength h = grid.RowDefinitions[0].Height;  grid.RowDefinitions[0].Height = GridLength.Auto; grid.UpdateLayout();   try {     var writeableBitmap = new WriteableBitmap((int)myDataGrid.ActualWidth, (int)myDataGrid.ActualHeight); } finally {     grid.RowDefinitions[0].Height = h;     grid.UpdateLayout(); } 
by : renhttp://stackoverflow.com/users/579026




No comments:

Post a Comment

Send us your comment related to the topic mentioned on the blog