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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T13:28:37+00:00 2026-05-29T13:28:37+00:00

Scratching my brain here…. I have the following ListBox <ListBox Height=221 HorizontalAlignment=Left Name=listBox1 VerticalAlignment=Top

  • 0

Scratching my brain here….

I have the following ListBox

    <ListBox Height="221" HorizontalAlignment="Left" Name="listBox1" VerticalAlignment="Top" Width="Auto" ItemsSource="{Binding MediaItems}">
        <ItemsControl.ItemTemplate>
            <DataTemplate>
                <Grid ShowGridLines="True">
                    <my:MediaItemControl CurrentItem="{Binding}" />

                </Grid>
            </DataTemplate>
        </ItemsControl.ItemTemplate>
    </ListBox>

The listbox is bound to an ObservableCollection of a object.

As you can see this ListBox includes a user control. Within the user control I have the following dependancy property information.

    public static readonly DependencyProperty CurrentItemProperty = DependencyProperty.Register("CurrentItem", typeof(TypedMediaItem), typeof(MediaItemControl), new PropertyMetadata(null));
    public TypedMediaItem  CurrentItem
    {
        get { return (TypedMediaItem)GetValue(MediaItemControl.CurrentItemProperty); }
        set { 
            SetValue(MediaItemControl.CurrentItemProperty, value);
        }
    }

What I am trying to do is pass the current item within the ItemsSource of the ListBox, to my usercontrol. However using the above methods doesnt work, the setter on the dependency property is never called.

What am I doing wrong?

  • 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-29T13:28:38+00:00Added an answer on May 29, 2026 at 1:28 pm

    Anything that binds to a DependencyProperty will not directly call the CLR property that you created. To actually know whether the DependencyProperty is changed, you need to create a PropertyChangedCallback as shown below.

    //Never used by xaml that binds to CurrentItem
    //Only used when referenced directly by C# code
    //Example: (obj as MediaItemControl).CurrentItem = new TypedMediaItem();
    public TypedMediaItem CurrentItem{
        get { return (TypedMediaItem) GetValue(CurrentItemProperty ); }
        set { SetValue(CurrentItemProperty , value); }
    }
    
    //Used by xaml binding
    public static readonly DependencyProperty CurrentItemProperty =
       DependencyProperty.Register("CurrentItem", typeof(TypedMediaItem),
       typeof(MediaItemControl), new PropertyMetadata(null, new PropertyChangedCallback(OnCurrentItemChanged)));
    
    private static void OnCurrentItemChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) {
        //TODO: Set break point here
        //If this code is executed, then the property was changed
        MediaItemControl instance = (MediaItemControl) d;
        TypedMediaItem newValue = (TypedMediaItem) e.NewValue;
        return;
    }
    

    This doesn’t answer your question exactly, but should help you debug a little farther.
    If you still can’t figure out what is wrong, then I’m going to more information because everything that you have provided looks correct to me. For example, the error you are getting or more code on the MediaItemControl. You could also upload the project somewhere and I could look at it.

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

Sidebar

Related Questions

Scratching my head here: I have an application which works fine in Debug+Release if
I have been scratching my head since long now to get rid of following
I'm sitting here scratching my head here, I should have 2 rows of 4
Scratching my head here... If I try the following with rails: User.limit(25).includes([:addresses]) I get:
I am scratching my head to figure out a solution to the following question:
I've been scratching my head over this for an hour... I have a list
I have been scratching my head for a while on this one. I dont
I'm really scratching my head on this one: I have an object (MyObject) which
I've been scratching my head for hours trying to figure this out. I have
I have been scratching my head all morning behind this but still haven't been

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.