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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T23:51:03+00:00 2026-06-13T23:51:03+00:00

I want to create a custom DependencyProperty for a usercontrol public Table Grids {

  • 0

I want to create a custom DependencyProperty for a usercontrol

 public Table Grids
    {
        get { return (Table)GetValue(GridsProperty); }
        set { SetValue(GridsProperty, value); }
    }

    // Using a DependencyProperty as the backing store for Grids.  This enables animation, styling, binding, etc...
    public static readonly DependencyProperty GridsProperty =
                DependencyProperty.Register("Grids", typeof(Table), 
                typeof(MyViewer), new UIPropertyMetadata(10));

Here Table is a custom datatype used to store rows & Columns. That will help me in using them like;

<my:MyViewer 
    HorizontalAlignment="Left" 
    Margin="66,54,0,0" 
    x:Name="MyViewer1" 
    VerticalAlignment="Top" 
    Height="400" 
    Width="400"
    Grids="10"/>

or

<my:MyViewer 
    HorizontalAlignment="Left" 
    Margin="66,54,0,0" 
    x:Name="MyViewer1" 
    VerticalAlignment="Top" 
    Height="400" 
    Width="400"
    Grids="10,20"/>

I tried to define the Table datatype as;

public class Table 
    {
        public int Rows { get; set; }
        public int Columns { get; set; }

        public Table(int uniform)
        {
            Rows = uniform;
            Columns = uniform;
        }

        public Table(int rows, int columns)
        {
            Rows = rows;
            Columns = columns;
        }
    }

but it’s not working; when i use Grids=”10″ in XAML it breaks.
Can anybody help me to achive this?

  • 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-06-13T23:51:05+00:00Added an answer on June 13, 2026 at 11:51 pm

    The default value in the property metadata is of the wrong type. This will result in an exception when the MyViewer class is loaded. Set the default value to e.g. new Table(10).

    Besides that, XAML/WPF will not automatically convert the strings "10" or "10,20" to instances of your Table class by calling the right constructors. You will have to write a TypeConverter to perform this conversion.

    A simple TypeConverter could look like this:

    public class TableConverter : TypeConverter
    {
        public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
        {
            return sourceType == typeof(string);
        }
    
        public override object ConvertFrom(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value)
        {
            string tableString = value as string;
            if (tableString == null)
            {
                throw new ArgumentNullException();
            }
    
            string[] numbers = tableString.Split(new char[] { ',' }, 2);
            int rows = int.Parse(numbers[0]);
            int columns = rows;
    
            if (numbers.Length > 1)
            {
                columns = int.Parse(numbers[1]);
            }
    
            return new Table { Rows = rows, Columns = columns };
        }
    }
    

    The TypeConverter would be associated with your Table class like this:

    [TypeConverter(typeof(TableConverter))]
    public class Table
    {
        ...
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i want to create custom object to get set value on it. -(id)initWithURLString:(NSString *)url
I want to create a custom set that will automatically convert objects into a
I want to create custom tag, but i get XML parsing error on JSPVersion
I want to create custom Toast view like public class SMSToast extends Activity {
I want to create custom AlertDialog, but without AlertDialog.Builder. I set ListView as content
i want create a custom json data from the mssql 2008 results so that
I want to create custom button and I need it to be circle. How
I want to create a custom navigation bar to put in my header.phtml file.
I want to create a custom property on one of my entities mapped from
I want to create a custom list in Flex for an interface prototype. The

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.