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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T03:37:12+00:00 2026-05-25T03:37:12+00:00

I have a custom usercontrol that does a little animation on a DispatcherTimer tick,

  • 0

I have a custom usercontrol that does a little animation on a DispatcherTimer tick, as well as update a DependencyProperty of that usercontrol :

public partial class EggCounter : UserControl
{
  DispatcherTimer eggTimer;

  public EggCounter()
  {
     // Required to initialize variables
     InitializeComponent();

     eggTimer = new DispatcherTimer();
     eggTimer.Interval = TimeSpan.FromSeconds(5);
     eggTimer.Tick += new EventHandler(eggTimer_Tick);
     eggTimer.Start();

     Eggs = 0;
  }

  void eggTimer_Tick(object sender, EventArgs e)
  {
     Eggs += 4;
     Pop.Begin();
     mePop.Play();
  }

  private void mePop_MediaEnded(object sender, RoutedEventArgs e)
  {
     mePop.Position = TimeSpan.FromSeconds(0);
  }

  /// <summary>
  /// The <see cref="Eggs" /> dependency property's name.
  /// </summary>
  public const string EggsPropertyName = "Eggs";
  /// <summary>
  /// Gets or sets the value of the <see cref="Eggs" />
  /// property. This is a dependency property.
  /// </summary>
  public int Eggs
  {
     get
     {
        return (int)GetValue(EggsProperty);
     }
     set
     {
        SetValue(EggsProperty, value);
     }
  }
  /// <summary>
  /// Identifies the <see cref="Eggs" /> dependency property.
  /// </summary>
  public static readonly DependencyProperty EggsProperty = DependencyProperty.Register(EggsPropertyName, typeof(int), typeof(EggCounter), new UIPropertyMetadata(0));
}

The XAML for this code is irrelevant. Then, I place this control on my MainPage, like this :

<my:EggCounter ToolTipService.ToolTip="{Binding RelativeSource={RelativeSource Self}, Path=Eggs, StringFormat='{} Our chickens have laid {0} eggs since you have been here.'}"/>

The page loads fine, but as soon as the timer fires, I get this error :

"The given key was not present in the dictionary."

in the Eggs property’s setter in my usercontrol, i.e. on this line :

SetValue(EggsProperty, value);

I’ve also tried an ElementBinding on the control, but get the same error. Am I doing something wrong with the dependency property?

  • 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-25T03:37:12+00:00Added an answer on May 25, 2026 at 3:37 am

    Your code contains UIPropertyMetaData. Silverlight does not have this class it uses just PropertyMetaData instead.

    Having said that the failure mode you describe seems to indicate that your code compiles, I don’t understand how even got that far.

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

Sidebar

Related Questions

I have an custom control that extend System.Web.UI.UserControl. Is it possible to inherit user
I have a custom login usercontrol that has a normal textbox and a passwordbox.
I have an usercontrol in silverlight that I'm trying to convert to custom control.
I have a custom UserControl that have a StatusStrip. So, I resize this control
I have a Custom UserControl . In that UserControl i have some buttons ,
I have a C# UserControl that hosts a TextBox. When the custom control is
First, please look at this custom Button-inherited UserControl code: Public Class UserControl1 Dim _Text
I have a nice little UserControl that is a draggable box with some text
I have a custom UserControl that I am drawing using the GDI+. It is
I have a UserControl that contains an ItemsControl with a custom ItemsPanel, with a

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.