Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8386607
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T17:59:14+00:00 2026-06-09T17:59:14+00:00

I have a listbox, whose ItemsSource is binding. Is there anyway to convert each

  • 0

I have a listbox, whose ItemsSource is binding. Is there anyway to convert each individual listbox item to an image of what is seen on the screen at runtime?

EDIT:

I have this right now, it doesn’t seem to be working though…

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");
        }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T17:59:16+00:00Added an answer on June 9, 2026 at 5:59 pm

    This code is working fine for me, i didn’t try to print the image since i don’t have a printer right now, but the image is correctly rendered in the test app i created

    var listBoxItem = listBox.ItemContainerGenerator.ContainerFromIndex(0) as ListBoxItem;
                RenderOptions.SetBitmapScalingMode(image, BitmapScalingMode.HighQuality);
                RenderTargetBitmap renderTargetBitmap = new RenderTargetBitmap((int)listBoxItem.ActualWidth,
                                                                               (int)listBoxItem.ActualHeight, 96, 96,
                                                                               PixelFormats.Pbgra32);
                renderTargetBitmap.Render(listBoxItem);
                image.Source = renderTargetBitmap;
                image.Width = listBoxItem.ActualWidth;
                image.Height = listBoxItem.ActualHeight;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a ListBox whose ItemsSource is bound to a list of objects. The
I have a listbox, which is defined like so: <ListBox ItemsSource={Binding Source={x:Static local:ResourceCollection.resourceList}} Height=143
I have a ListBox whose datacontext is an: ObservableCollection<Item> Item is a base class,
I have a ListBox whose ItemsSource is databound to a list of ints. I'd
I have something like this: <ListBox ItemsSource={Binding List}> <ListBox.ItemContainerStyle> <Style TargetType=ListBoxItem> <Setter Property=HorizontalContentAlignment Value=Stretch></Setter>
I don't know what I'm doing wrong here. I have a ListBox whose DataContext
I have an ASP.NET page with a listbox whose selection mode is set to
In my MainWindow, I've got a ListBox whose ItemsSource is bound to an ObservableCollection
I have a ListBox whose ItemsPanel I have replaces with a WrapPanel. The WrapPanel
I have a listbox whose values are generated dynamically. The list box contains months

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.