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

  • Home
  • SEARCH
  • 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 872793
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T10:50:11+00:00 2026-05-15T10:50:11+00:00

I have created a custom ItemsControl called Toolbox. I want to be able to

  • 0

I have created a custom ItemsControl called Toolbox. I want to be able to display images in that Toolbox – it is a part of a diagram designer.

My xaml looks like this:

<d:Toolbox ItemsSource="{Binding}">
                            <ItemsControl.ItemTemplate>
                                <DataTemplate>

                                    <Image Source="{Binding Library}"/>

                                </DataTemplate>

                            </ItemsControl.ItemTemplate>
                        </d:Toolbox>

and my ViewModel:

 public ObservableCollection<ElectricalLibrary> l = null;
        public ObservableCollection<Image> _images = null;
        public ObservableCollection<Image> Library

        {
            get
            {
                if (l == null)
                {
                    DataAccessLayerClass dc = new DataAccessLayerClass();
                    dc.LoadComponents();
                    l = dc.Library;
                    foreach (ElectricalLibrary lib in l) { 
                        Image finalImage = new Image();
                        finalImage.Width = 80;
                        BitmapImage logo = new BitmapImage();
                        logo.BeginInit();
                        logo.UriSource = new Uri(lib.url.ToString());
                        logo.EndInit();

                        finalImage.Source = logo;
                        MessageBoxResult result = MessageBox.Show(logo.UriSource.ToString());  

                        _images.Add(finalImage);
                    }



                }
                return _images;
            }
            set { _images = value; }
        }

Ands this is a resource file for Toolbox itself:

<Style TargetType="{x:Type s:Toolbox}">
        <Setter Property="SnapsToDevicePixels"
                Value="true" />
        <Setter Property="Focusable"
                Value="False" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate>
                    <Border BorderThickness="{TemplateBinding Border.BorderThickness}"
                            Padding="{TemplateBinding Control.Padding}"
                            BorderBrush="{TemplateBinding Border.BorderBrush}"
                            Background="{TemplateBinding Panel.Background}"
                            SnapsToDevicePixels="True">
                        <ScrollViewer VerticalScrollBarVisibility="Auto">
                            <ItemsPresenter SnapsToDevicePixels="{TemplateBinding UIElement.SnapsToDevicePixels}" />
                        </ScrollViewer>
                    </Border>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
        <Setter Property="ItemsPanel">
            <Setter.Value>
                <ItemsPanelTemplate>
                    <WrapPanel Margin="0,5,0,5"
                               ItemHeight="{Binding Path=DefaultItemSize.Height, RelativeSource={RelativeSource AncestorType=s:Toolbox}}"
                               ItemWidth="{Binding Path=DefaultItemSize.Width, RelativeSource={RelativeSource AncestorType=s:Toolbox}}" />
                </ItemsPanelTemplate>
            </Setter.Value>
        </Setter>
    </Style>

I store only the URLs of the images in the database, the images are stored on a disc. I take the entity object and create an image, add it into an ObservableCollection of images and bind Image control to LIbrary in xaml.

Obviously, the code does not work. But how to make it work? The list with images is loaded correctly.

Thanks for help.

  • 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-15T10:50:12+00:00Added an answer on May 15, 2026 at 10:50 am

    ****EDIT****
    Right – I have managed to get the code to work after some changes. Change your Library property to return a list of Uri’s set from your database Objects – make sure you actually return something. I suggest the following for your property (change it if you need a more robust property which doesnt refetch every time there is get…

    public ObservableCollection<Uri> Library
    {
        get
        {
            OberservableCollection<Uri> library = new OberservableCollection<Uri>();
            DataAccessLayerClass dc = new DataAccessLayerClass();
            dc.LoadComponents();
    
            foreach (ElectricalLibrary lib in dc.Library)
            {
                library.Add(new Uri(lib.url.ToString()));
            }
    
            return library;
        }
    

    Then your XAML can look like this:

                          <d:Toolbox ItemsSource="{Binding Library}">
                                <ItemsControl.ItemTemplate>
                                    <DataTemplate>
    
                                        <Image Source="{Binding}"/>
    
                                    </DataTemplate>
    
                                </ItemsControl.ItemTemplate>
                            </d:Toolbox>
    

    Doing this makes it work fine for me.

    Original text left for historical reasons

    You seem to be binding the image to the entire collection. If it is just a single list of images you need then the ItemsSource of you toolbox should be the Library collection with an image as part of the DataTemplate (I cant test this right now so it may not be 100% accurate code)

    <d:Toolbox ItemsSource="{Binding Library}">
        <ItemsControl.ItemTemplate>
            <DataTemplate>
                    <Image Source="{Binding}"/>
            </DataTemplate>
        </ItemsControl.ItemTemplate>
    </d:Toolbox>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a custom user control in XAML that creates a ItemsControl which ItemsPanel
I have created custom posts and I want one page in my site to
I have created custom jQuery UI widget called uiPopover, very similar to UI-dialog (in
I have created a custom method that will return unique items, together with the
I have created a custom user control, which is basicly a ItemsControl with it's
I have created a custom attribute that I am using on my class MyClass
I'm creating a custom control called FooControl derived from ItemsControl have a default style
I have created custom listview in that have list of textview & list of
I have created Custom Dialog for my application. While i run that application in
I have created custom result class to serialize json data to xml. I want

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.