ItemsSource がバインドされているリストボックスがあります。個々のリストボックス項目を実行時に画面に表示される画像に変換する方法はありますか?
編集:
私は今これを持っていますが、機能していないようです...
ListBoxItem item = new ListBoxItem();
item = (ListBoxItem)(lb1.ItemContainerGenerator.ContainerFromIndex(0));
//itempres = item.Content as ItemsPresenter;
//double width = itempres.ActualWidth;
//double height = itempres.ActualHeight;
double width = item.Width;
double height = item.Height;
//RenderTargetBitmap bmpCopied = new RenderTargetBitmap((int)Math.Round(width), (int)Math.Round(height), 100, 100, PixelFormats.Default);
RenderTargetBitmap bmpCopied = new RenderTargetBitmap(100, 500, 100, 100, PixelFormats.Default);
DrawingVisual drawingVisual = new DrawingVisual();
using (DrawingContext drawingContext = drawingVisual.RenderOpen())
{
VisualBrush visualBrush = new VisualBrush(item);
drawingContext.DrawRectangle(visualBrush, null, new Rect(new Point(), new Size(width, height)));
}
bmpCopied.Render(drawingVisual);
displayImage = new Image();
displayImage.Source = bmpCopied;
fd.Blocks.Add(new BlockUIContainer(displayImage));
//ListBox lbNew = new ListBox();
//lbNew.Style = lb1.Style;
//lbNew.ItemsSource = lb1.ItemsSource;
//lbNew.ItemContainerStyle = lb1.ItemContainerStyle;
//lbNew.ItemTemplateSelector = lb1.ItemTemplateSelector;
//UIElement elementAll = lbNew as UIElement;
//fd.Blocks.Clear();
//fd.Blocks.Add(new BlockUIContainer(elementAll));
//}
PrintDialog pd = new PrintDialog();
if (pd.ShowDialog() == true)
{
fd.PageHeight = pd.PrintableAreaHeight;
fd.PageWidth = pd.PrintableAreaWidth;
fd.PagePadding = new Thickness(96);
IDocumentPaginatorSource dps = fd;
pd.PrintDocument(dps.DocumentPaginator, "flow doc");
}