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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T14:16:38+00:00 2026-06-04T14:16:38+00:00

I am designing a control that can have two main states. The state will

  • 0

I am designing a control that can have two main states. The state will be set via a dependence property. I would like to set the property via XAML. I know that the setter will only run the setValue code if it is set via XAML as explained here: WPF: XAML property declarations not being set via Setters?

So I’ve tried to set up a DependencyPropertyChangedEvent event, but when I run my code I get this error:

XamlParseException Occurred
'The invocation of the constructor on type 'RouteOneClient.VehicleInfoControl'
that matches the specified binding constraints threw an exception.' Line number 
'134' and line position '34'.

When I look through that, it tells me that I cannot create a new instance of my control in my event. The C# logic looks like this:

    public enum VehicleType
    {
        Sale = 1,
        Trade = 2,
    }

    public static readonly DependencyProperty VehicleTypeProperty =  DependencyProperty.Register(
        "VehicleTYPE", 
        typeof(VehicleType), 
        typeof(VehicleInfoControl), 
        new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.AffectsRender, new PropertyChangedCallback(OnVehTypeChanged)));  // optionally metadata for defaults etc.

    public VehicleInfoControl()
    {
        InitializeComponent();
    }

    public VehicleType VehicleTYPE
    {
        get { return (VehicleType)GetValue(VehicleTypeProperty); }
        set
        {
            SetValue(VehicleTypeProperty, value);
        }          
    }

    private static void OnVehTypeChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
    {
        VehicleInfoControl instance = d as VehicleInfoControl;

        if (instance.VehicleTYPE == VehicleType.Sale)
        {
            instance.TitleLabel.Content = "Sale Vehicle";
            instance.IntendedUse.Visibility = System.Windows.Visibility.Visible;
            instance.VehicleNewUsed.Visibility = System.Windows.Visibility.Visible;
            instance.VehicleVin.Visibility = System.Windows.Visibility.Visible;
            instance.VehicleInceptionMiles.Visibility = System.Windows.Visibility.Visible;
            instance.IntendedUseLabel.Visibility = System.Windows.Visibility.Visible;
            instance.VehicleNewUsedLabel.Visibility = System.Windows.Visibility.Visible;
            instance.VehicleVinLabel.Visibility = System.Windows.Visibility.Visible;
            instance.VehicleInceptionMilesLabel.Visibility = System.Windows.Visibility.Visible;
        }
        else
        {
            instance.TitleLabel.Content = "Trade Vehicle";
            instance.IntendedUse.Visibility = System.Windows.Visibility.Hidden;
            instance.VehicleNewUsed.Visibility = System.Windows.Visibility.Hidden;
            instance.VehicleVin.Visibility = System.Windows.Visibility.Hidden;
            instance.VehicleInceptionMiles.Visibility = System.Windows.Visibility.Hidden;
            instance.IntendedUseLabel.Visibility = System.Windows.Visibility.Hidden;
            instance.VehicleNewUsedLabel.Visibility = System.Windows.Visibility.Hidden;
            instance.VehicleVinLabel.Visibility = System.Windows.Visibility.Hidden;
            instance.VehicleInceptionMilesLabel.Visibility = System.Windows.Visibility.Hidden;
        }
    }

And the XAML:

<Expander Header="Vehicle Information" Width="Auto" Height="Auto" Grid.Row="2">
    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*" />
            <ColumnDefinition Width=".3*" />
            <ColumnDefinition Width="*" />
        </Grid.ColumnDefinitions>

        <custom:VehicleInfoControl x:Name="SaleVeh" Width="Auto" Height="Auto" Grid.Column="0" VehicleTYPE="Sale"/>
        <custom:VehicleInfoControl x:Name="TradeVeh" Width="Auto" Height="Auto" Grid.Column="2" VehicleTYPE="Trade"/>

    </Grid>
</Expander>

The error given above points to the line.

I feel like I’m following the form correctly, but it isn’t running. Any ideas?

  • 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-04T14:16:40+00:00Added an answer on June 4, 2026 at 2:16 pm

    The type of your dependency property is an enum, which is a ValueType, but you specify null as default property value in your property metadata. That won’t work, since null is not a valid value for a ValueType.

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

Sidebar

Related Questions

I would like to create a UserControl that will have some behavior(animated collapsing...) and
In a WPF page that I'm designing for my church, I have two ListBox
while designing my user control, i encountered the following problem: i would like to
So I'm designing a myspace page and I have two images, one is a
I'm a relative VBA novice, and designing a fairly complex macro that can run
So the thing is that I have a main ControlTemplate which defines the most
I am designing an ASP.NET MVC3 application, and I would like to have a
Assuming you have a business that rents movie and you were designing a schema
I have pages within a site containing a control that uses a query string
I have two interfaces: IState and IAction . A State has a method: GetActions

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.