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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T02:27:43+00:00 2026-06-02T02:27:43+00:00

When you have a usercontrol in wpf can it reach outside to its parent

  • 0

When you have a usercontrol in wpf can it reach outside to its parent elements? For instance my user control just lists some generic things which are held inside the control which is encapsulated within a dockpanel on the main window, but I have a textbox and button in the main window that I would like to access from the control… is this possible?

It would save me alot of time rather than changing the content of the entire window and displaying the same textbox/button in every usercontrol. If anyone has an example of this it would be much appreciated.

  • 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-02T02:27:45+00:00Added an answer on June 2, 2026 at 2:27 am

    Yes it is possible and here is some code I have used to compose presentations out of UserControls that have DPs.

    I don’t love it even a little, but it works. I also think this is a great topic and maybe some code will help get some better answers!

    Cheers,
    Berry

    UserControl XAML

    <Button x:Name="btnAddNewItem" Style="{StaticResource blueButtonStyle}" >
        <StackPanel Orientation="Horizontal">
            <Image Source="{resx:Resx ResxName=Core.Presentation.Resources.MasterDetail, Key=bullet_add}" Stretch="Uniform" />
            <Label x:Name="tbItemName" Margin="5" Foreground="White" Padding="10, 0">_Add New [item]</Label>
        </StackPanel>
    </Button>
    

    UserControl Code Behind

    public partial class AddNewItemButton : UserControl
    {
        ...
    
        #region Item Name
    
        public static readonly DependencyProperty ItemNameProperty = DependencyProperty.Register(
            "ItemName", typeof(string), typeof(AddNewItemButton),
            new FrameworkPropertyMetadata(OnItemNameChanged));
    
        public string ItemName
        {
            get { return (string)GetValue(ItemNameProperty); }
            set { SetValue(ItemNameProperty, value); }
        }
    
        public string ButtonText { get { return (string) tbItemName.Content; } }
    
        private static void OnItemNameChanged(DependencyObject obj, DependencyPropertyChangedEventArgs args)
        {
            // When the item name changes, set the text of the item name
            var control = (AddNewItemButton)obj;
    
            control.tbItemName.Content = string.Format(GlobalCommandStrings.Subject_Add, control.ItemName.Capitalize());
            control.ToolTip = string.Format(GlobalCommandStrings.Subject_Add_ToolTip, control.ItemName);
        }
    
        #endregion
    
        #region Command
    
        public static readonly DependencyProperty CommandProperty = DependencyProperty.Register(
            "Command", typeof(ICommand), typeof(AddNewItemButton),
            new FrameworkPropertyMetadata(OnCommandChanged));
    
        public ICommand Command
        {
            get { return (ICommand)GetValue(CommandProperty); }
            set { SetValue(CommandProperty, value); }
        }
    
        private static void OnCommandChanged(DependencyObject obj, DependencyPropertyChangedEventArgs args)
        {
            // When the item name changes, set the text of the item name
            var control = (AddNewItemButton)obj;
            control.btnAddNewItem.Command = control.Command;
        }
    
        #endregion
    
    }
    

    enter image description here

    Another UserControl showing Composition

    <UserControl ...
             xmlns:uc="clr-namespace:Smack.Core.Presentation.Wpf.Controls.UserControls" 
             >
    
        <DockPanel LastChildFill="True">
            ...
            <uc:AddNewItemButton x:Name="_addNewItemButton" Margin="0,0,10 0" DockPanel.Dock="Right"  />
            ...
        </DockPanel>
    </UserControl>
    

    enter image description here

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

Sidebar

Related Questions

I have created a UserControl in WPF. This user control consists of a border,
I have a WPF UserControl representing a Person with many fields. Some Persons can
I have c# winform application and one WPF user control. How i can add
WPF controls have certain properties (UserControl.Resources, UserControl.CommandBindings) that can have items added to them
I have a WPF TabControl which displays UserControl s. Some UserControl s are larger
Another WPF question for you all. I have a user control that contains a
I have a WPF user control with a number of textboxes, this is hosted
I have a wpf user control which exposes an IEnumerable ItemsSource DependencyProperty. I bind
I have a WPF application that contains some Window s with few UserControl s
In my WPF application, I have a Canvas object that contains some UserControl objects.

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.