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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T19:07:23+00:00 2026-05-13T19:07:23+00:00

I have a WPF UserControl containing a custom DependencyProperty named MyDP. I want to

  • 0

I have a WPF UserControl containing a custom DependencyProperty named MyDP. I want to bind this to a property on my ViewModel (which is injected as the UserControl’s DataContext). I know one way to do it by setting the binding in the UserControl’s declaration in the parent window’s XAML as such:

<Window x:Class="MyNamespace.Views.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:views="clr-namespace:MyNamespace.Views">
    <StackPanel>
        <views:MyControl MyDP="{Binding Path=MyVMProperty, Mode=OneWayToSource}"/>
    </StackPanel>
</Window>

This works fine, but as an alternate could I set up the binding inside the UserControl’s XAML, similar to how I set the bindings for the individual controls inside the UserControl to other properties of the ViewModel?

  • 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-13T19:07:23+00:00Added an answer on May 13, 2026 at 7:07 pm

    You can’t do what you were originally thinking directly. You probably tried and got some compile errors. You can’t set a custom property inline in the UserControl’s root XAML because the element type is UserControl so the compiler is enforcing property names based on that type, not your custom type. You could get around this by changing to an Attached Property but that actually changes the meaning of MyDP. Instead you can set a default in the Style for the UserControl and get an additional benefit of being able to override it on any declared instance by just doing what’s in your original example. Set this under your UserControl’s root element:

    <UserControl.Style>
        <Style>
            <Setter Property="views:MyControl.MyDp" Value="{Binding Path=MyVMProperty, Mode=OneWayToSource}" />
        </Style>
    </UserControl.Style>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a wpf user control which exposes an IEnumerable ItemsSource DependencyProperty. I bind
Currently I have a WPF project with a custom UserControl. This control contains a
I have got some custom WPF UserControl . And it has implementation like this
I have a WPF UserControl with binding converters referenced like this: <UserControl x:Class=MyControl x:Name=MyControl
I have a WPF TabControl which displays UserControl s. Some UserControl s are larger
I have created a UserControl in WPF. This user control consists of a border,
I have WPF userControl Library project. In it I have window which has next
I have a WPF UserControl. The code behind file declares some RoutedUICommand objects which
I am using WPF UserControl and I have a grid so I want to
I Have A wpf UserControl with a property: private IEnumerable<PropertyBase> properties; public IEnumerable<PropertyBase> Properties

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.