Windows phone 7 呈现UserControl+;WriteableBitmap中的ItemsControl?
我想使用WriteableBitmap将编程实例化的UserControl渲染为jpg/png图像,并将其用作Windows Phone 7.1项目中的实时平铺背景图像,但在渲染控件时,数据绑定未按预期工作 一般来说,UserControl是这样的:Windows phone 7 呈现UserControl+;WriteableBitmap中的ItemsControl?,windows-phone-7,silverlight-3.0,windows-phone-7.1,Windows Phone 7,Silverlight 3.0,Windows Phone 7.1,我想使用WriteableBitmap将编程实例化的UserControl渲染为jpg/png图像,并将其用作Windows Phone 7.1项目中的实时平铺背景图像,但在渲染控件时,数据绑定未按预期工作 一般来说,UserControl是这样的: <UserControl> <Grid x:Name="LayoutRoot" Height="173" Width="173" > <Grid.Background > <Soli
<UserControl>
<Grid x:Name="LayoutRoot" Height="173" Width="173" >
<Grid.Background >
<SolidColorBrush Color="{StaticResource PhoneAccentColor}" />
</Grid.Background >
<Grid.RowDefinitions>
<RowDefinition Height="27"/>
<RowDefinition Height="146"/>
</Grid.RowDefinitions >
<ItemsControl Grid.Row="1" Margin="10,0,0,0" ItemsSource="{Binding}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding MyBindingProperty, FallbackValue=xxx}" />
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
<TextBlock Text="Hello World" FontSize="22" Margin="5,0,0,0"/>
<TextBlock TextWrapping="Wrap" Text="{Binding Count, FallbackValue=-1}" FontSize="18.667" Margin="123,0,0,0"/>
</Grid>
</UserControl>
在通过可写位图进行渲染时,DataTemplate中的数据绑定有什么问题?我如何解决这个问题?我认为,您的控件尚未完全创建,并且在创建后无法获取位图。尝试使用
Dispatcher.BeginInvoke
或其他方法延迟抓取图像
另外,将此控件添加到页面中,并查看哪里有问题-在控件创建中还是在位图中?这将为您提供有关问题的更多信息
var tile = new MyTileControl { DataContext = this._myList };
tile.Arrange(new Rect(0, 0, 173, 173));
tile.Measure(new Size(173, 173));
var bmp = new WriteableBitmap(173, 173);
bmp.Render(tile, null);
bmp.Invalidate();