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

The Archive Base Latest Questions

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

I was trying to use tis depencency property in my code but it gives

  • 0

I was trying to use tis depencency property in my code but it gives me error says that Default value type does not match type of property ‘MyProperty’.
But short should accept 0 as default value.

If I try to give it a null as default value it works, even if its a non nullabel type.
How come this happens..

public short MyProperty
{
   get { return (short)GetValue(MyPropertyProperty); }
   set { SetValue(MyPropertyProperty, value); }
}

Using a DependencyProperty as the backing store for MyProperty. This enables animation, styling, binding, etc…

public static readonly DependencyProperty MyPropertyProperty =
    DependencyProperty.Register(
        "MyProperty",
        typeof(short),
        typeof(Window2),
        new UIPropertyMetadata(0)
    );
  • 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:36:00+00:00Added an answer on May 14, 2026 at 7:36 am

    The problem is that the C# compiler interprets literal values as integers. You can tell it to parse them as longs or ulongs (40L is a long, 40UL is ulong), but there isn’t an easy way to declare a short.

    Simply casting the literal will work:

    public short MyProperty
    {
        get { return (short)GetValue(MyPropertyProperty); }
        set { SetValue(MyPropertyProperty, value); }
    }
    
    public static readonly DependencyProperty MyPropertyProperty = 
       DependencyProperty.Register(
          "MyProperty", 
          typeof(short),
          typeof(Window2),
          new UIPropertyMetadata((short)0)
       );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to use reflection to collect a property from a class that
I'm trying to write a class that has a generic member variable but is
I am trying use filehelpers class builder but I am kinda confused on what
I was trying use svn to find a checkin using svn log, but it
I am trying use std::copy to copy from two different iterator. But during course
Is it at all possible to use Type Erasure to create objects that encapsulate
I am trying use Thread but i have some problem (I am beginner at
We use boost - so using that library should be fine. But I've never
I am trying use the jQuery table sorter plugin for a table that is
I'm trying use this code to get image resolution from file bool GetImageSizeEx(const char

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.