【问题标题】:take image of full datagrid拍摄完整数据网格的图像
【发布时间】:2012-12-07 09:05:44
【问题描述】:

我有:

<Grid>
 <Grid.RowDefinitions>
   <RowDefinition></RowDefinition>
 </Grid.RowDefinitions>

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

</Grid>

请注意,行定义中没有Height="Auto",因此数据网格占据了所有高度。 我正在尝试制作 full 数据网格的图片(包括需要滚动的不可见空间)。我试过了:

ImageExtensions.ToImage(myDataGrid);

还有

var writeableBitmap = new WriteableBitmap(pixelWidth, pixelHeight);

其中 pixelHeight 是使用 SizeChanged 事件或 DesiredSize 属性获得的。

一切都是徒劳的。高度始终是屏幕的高度。如果我在行定义中使用 auto="height" 那么它会起作用,但是当它太大时,datagrid 不会占用所有空间/或没有滚动条。

有人设法让它工作吗?

【问题讨论】:

    标签: silverlight datagrid silverlight-4.0


    【解决方案1】:

    解决方法:

    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();
    }
    

    【讨论】:

      猜你喜欢
      • 2020-07-06
      • 2013-03-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-02-03
      • 2015-04-18
      • 1970-01-01
      • 2017-12-25
      相关资源
      最近更新 更多