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 734643
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T07:23:48+00:00 2026-05-14T07:23:48+00:00

LowDown: I am trying to create a Document Viewer in WPF. It will allow

  • 0

LowDown: I am trying to create a Document Viewer in WPF. It will allow the user to preview selected documents and if they want, compare the documents in WPF. So they can view them side by side.

The layout is this: Left side is a full list box. On the right side is a Collection or an Items control. Inside the items control will be a collection of the “selected documents” in the list box. So A user can select multiple items in the list box and for each new item they select, they can add the item to the collection on the right. I want the collection to look like a image gallery that shows up in Google/Bing Image searches. Make sense?

The problem I am having is I can’t get the WPFPreviewer to bind correctly to the selected item in the list box under the itemscontrol.

Side Note: The WPFPreviewer is something Micorosft puts out that allows us to preview documents. Other previewers can be built for all types of documents, but im going basic here until I get this working right.

I have been successful in binding to the list box WITHOUT the items control here:

<Window.Resources>
    <DataTemplate x:Key="listBoxTemplate">
        <StackPanel Margin="3" >
            <DockPanel >
                <Image Source="{Binding IconURL}" Height="30"></Image>
                <TextBlock Text="  " />
                <TextBlock x:Name="Title" Text="{Binding Title}" 
                    FontWeight="Bold" />
                <TextBlock x:Name="URL" Visibility="Collapsed" 
                    Text="{Binding Url}"/>
            </DockPanel>
        </StackPanel>
    </DataTemplate>
</Window.Resources>
<Grid Background="Cyan">
    <ListBox HorizontalAlignment="Left" 
        ItemTemplate="{StaticResource listBoxTemplate}" Width="200" 
        AllowDrop="True" x:Name="lbDocuments" 
        ItemsSource="{Binding Path=DocumentElements,ElementName=winDocument}"       
        DragEnter="documentListBox_DragEnter"  />
    <l:WPFPreviewHandler
        Content="{Binding ElementName=lbDocuments, Path=SelectedItem.Url}"/>
</Grid>

Though, once I add in the ItemsControl, I can’t get it to work anymore:

<Window.Resources>
    <DataTemplate x:Key="listBoxTemplate">
        <StackPanel Margin="3" >
            <DockPanel >
                <Image Source="{Binding IconURL}" Height="30"></Image>
                <TextBlock Text="  " />
                <TextBlock x:Name="Title" Text="{Binding Title}" FontWeight="Bold" />
                <TextBlock x:Name="URL" Visibility="Collapsed" Text="{Binding Url}"/>
            </DockPanel>
        </StackPanel>
    </DataTemplate>
</Window.Resources>
<Grid>
    <ListBox HorizontalAlignment="Left" 
        ItemTemplate="{StaticResource listBoxTemplate}" Width="200" 
        AllowDrop="True" x:Name="lbDocuments" 
        ItemsSource="{Binding Path=DocumentElements,ElementName=winDocument}"
        DragEnter="documentListBox_DragEnter"  />
    <ItemsControl x:Name="DocumentViewer"  
        ItemsSource="{Binding ElementName=lbDocuments, Path=SelectedItem.Url}" >
        <ItemsControl.ItemTemplate>
            <DataTemplate>
                <Grid Background="Cyan">
                    <l:WPFPreviewHandler Content="{Binding Url}"/>
                </Grid>
            </DataTemplate>
        </ItemsControl.ItemTemplate>
    </ItemsControl>
</Grid>

Here is the Class of which is loaded into the ListBox

    public class Document
{
    public string Title { get; set; } 
    public string Url { get; set; } //this is what I want
    public string IconURL { get; set; } //used so I can display the icon of the file
}

Can someone please help me out with trying to bind to the ItemsControl if I select one or even multiple items in the listbox.

  • 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-05-14T07:23:48+00:00Added an answer on May 14, 2026 at 7:23 am

    It looks like the error is in your ItemsSource binding. Currently, you are trying to set the ItemsControl to display the Url of the SelectedItem. Instead, you should just bind to the SelectedItems (the s on the property name is really important!) property:

    ...
    <ItemsControl x:Name="DocumentViewer"  
        ItemsSource="{Binding ElementName=lbDocuments, Path=SelectedItems}" >
    ...
    

    Since you already have a DataTemplate that is using the Url to create the PreviewHandler, this should do what you need.

    Edit
    You need to bind to SelectedItems, and not SelectedItem because SelectedItem is only one object (not a valid ItemsSource), whereas SelectedItems is an IEnumerable of all the items selected.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 487k
  • Answers 487k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Neither of these supports transactions in the sense of the… May 16, 2026 at 8:21 am
  • Editorial Team
    Editorial Team added an answer 222.22.222.22. But it sounds like you are starting up a… May 16, 2026 at 8:21 am
  • Editorial Team
    Editorial Team added an answer Make sure you call Inject() on the IKernel instance and… May 16, 2026 at 8:21 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Related Questions

No related questions found

Top Members

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.