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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T21:05:32+00:00 2026-05-16T21:05:32+00:00

I have a Silverlight user control that has an Image control within it. This

  • 0

I have a Silverlight user control that has an Image control within it. This image needs to be set by another page that contains the above mentioned control, through a datamember of a bound list of items. Currently, the image does not get set when the URL is sent through to the user control. In actual fact, no code other than the SetValue(ImageSourceProperty, value); seems to be hit.

The XAML in the user control looks as follows:

<Grid x:Name="LayoutRoot" Background="Black">
    <Image Name="ContentImage"/>
</Grid>

In the code behind of that I have a DependencyObject set to receive the URL of the image and set the datasource of the image:

        public static DependencyProperty ImageSourceProperty =
    DependencyProperty.Register("ImageSource", typeof(String), typeof(MediaItemControl), null);

public String ImageSource
    {
        get { return (String)GetValue(ImageSourceProperty); }
        set
        {
            SetValue(ImageSourceProperty, value);
            Dispatcher.BeginInvoke(() => this.ContentImage.Source = new BitmapImage(new Uri(value, UriKind.RelativeOrAbsolute)));
        }
    }

The MainPage.Xaml holds a reference to this user control within an ItemsTemplate who’s itemssource gets set in the code behind to a list of objects, which has a property called ImageURL. This datasource is set correctly in the code behind. This is the XAML for the MainPage:

<UserControl x:Class="ExampleSilverlightApp.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:medc="clr-namespace:ExampleSilverlightApp.Controls" mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="400">

<Grid x:Name="LayoutRoot" Background="White">
    <StackPanel Name="ItemsControlStackPanel">
        <ItemsControl Name="ContentItemControl" Visibility="Visible">
            <ItemsControl.ItemsPanel>
                <ItemsPanelTemplate>
                    <StackPanel Orientation="Horizontal"  />
                </ItemsPanelTemplate>
            </ItemsControl.ItemsPanel>
            <ItemsControl.ItemTemplate>
                <DataTemplate>
                    <Grid Width="126" HorizontalAlignment="Center">
                        <medc:MediaItemControl x:Name="CustomMediaItemControl"   
                                               ImageSource="{Binding ImageURL}"
                                               >
                        </medc:MediaItemControl>
                    </Grid>
                </DataTemplate>
            </ItemsControl.ItemTemplate>
        </ItemsControl>
    </StackPanel>
</Grid>

The issue I have is that the image source does not get set on the user control. The setter of the dependency object doesnt appear to be hit. If I put a button on the control that when pressed sets the ImageSource property, the set is then hit and the image is displayed. The interesting part is that the ImageSource value HAS actually been set correctly, but the image’s datasource is null until set using the button.

Does anyone have any ideas as to why this is happening?

  • 1 1 Answer
  • 1 View
  • 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-16T21:05:33+00:00Added an answer on May 16, 2026 at 9:05 pm

    Try setting the ContentImage.Source in the PropertyChangedCallback delegate of the Dependency property – like this :

    public static DependencyProperty ImageSourceProperty = 
    DependencyProperty.Register("ImageSource", typeof(String), typeof(MediaItemControl), 
        new PropertyMetadata(delegate(DependencyObject sender, DependencyPropertyChangedEventArgs args)
                {
                    (sender as MediaItemControl).ContentImage.Source = new BitmapImage(new Uri((string)args.NewValue, UriKind.RelativeOrAbsolute));
                }));
    

    When you databind, the databinding engine in the background calls DependencyObject.SetValue(ImageSourceProperty, newValue) and doesn’t refer to the actual propery (ie – it doesn’t call MediaItemControl.ImageSource = newValue) – hence the logic in the setter doesn’t get called.

    HTH !

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

Sidebar

Related Questions

I have a Silverlight user control that has several canvas controls within a Stack
I have a button and image inside it in my silverlight user control. When
I have a user control in silverlight which contains both XMAL and .cs file.
I have a silverlight application that contains Bing map. I want when the user
I'm just getting started with silverlight. Basically I have a silverlight user control that
I currently have a user control that contains items that have a certain X,
I have a silverlight control that has a Frame on it. I want to
I have an existing Silverlight application where Page.xaml has some buttons on it that
I have created a lookless control using silverlight 4. This control contains a textbox
I have a custom base user control in silverlight. <UserControl x:Class=Problemo.MyBaseControl xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml xmlns:d=http://schemas.microsoft.com/expression/blend/2008

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.