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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T02:25:39+00:00 2026-06-09T02:25:39+00:00

EDIT: Figured it out, problem was not creating the name scope and registering the

  • 0

EDIT: Figured it out, problem was not creating the name scope and registering the name. Now working, will provide an answer below.

ORIGINAL QUESTION:

I think I’m doing something wrong when programatically adding controls to my WPF screen.

Been banging on this prototype of a drag-and-drop configurable UI that lets you save and load layouts using the WPF DevEx LayoutControl.

It was working, but I broke it when I went from using a static WPF screen made in Visual Studio to a screen that had FrameworkElements added programatically.

Here is a simple test of adding an element to a LayoutControl:

    public static void InstallItemsInLayoutControl(LayoutControl layoutControl)
    {
        // FAKE TEST VERSION
        Button btn = new Button();
        btn.Name = "TESTBUTTON";
        btn.Content = "Test Me";
        btn.Height = 23;
        btn.Width = 100;
        btn.HorizontalAlignment = HorizontalAlignment.Left;
        btn.VerticalAlignment = VerticalAlignment.Top;
        btn.Width = 100;

        layoutControl.Children.Add(btn);
    }

For the results below, this is the only item added to an otherwise empty screen.

When I load this screen up and enable the drag-and-drop editing mode, sure enough that button is present. It’s not visible, but I can pull it into the screen from the available items, move it around, and save the layout to XML that looks good. For example, here is a trivial layout of nothing on the screen but this button, at the top level:

  <?xml version="1.0" encoding="utf-8" ?> 
- <LayoutControl Orientation="Vertical">
  <Element ID="TESTBUTTON" HorizontalAlignment="Left" VerticalAlignment="Top" Width="100" Height="23" /> 
  <AvailableItems /> 
  </LayoutControl

If I remove the Button from the screen and save, the XML correctly looks different:

  <?xml version="1.0" encoding="utf-8" ?> 
- <LayoutControl Orientation="Vertical">
- <AvailableItems>
  <Element ID="TESTBUTTON" HorizontalAlignment="Left" VerticalAlignment="Top" Width="100" Height="23" /> 
  </AvailableItems>
  </LayoutControl>

(note the button is no longer in the layout, but rather in the available items)

I have looked at the DevEx code, and the take the ID from the XML element, and they pass it to FrameworkElement.FindName(string), which documentation says looks at the Name property.

There seems to be a match between the ID and the Name property of my runtime object.

Looking in the WPF Tree Visualizer, I see in the visual tree that the hierarchy looks like this when I first show this screen:

AdornerDecorator->AvalonAdapter->LayoutControl->ItemsContainer->TESTBUTTON

I am not sure what this indirection of the ItemsContainer is, but I suspect it is the “available items” container, which is where stuff not on the screen but available to be customized onto it hangs out.

The visualizer shows that the Name property at runtime is indeed TESTBUTTON.

This exact scenario was working with the items not being added programatically, and I guess my next step is to put some design-time elements in there as well.

But I’m very new to WPF, is there anything obvious that I’m doing wrong in how I add my button that might expalin this?

Thanks.

  • 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-09T02:25:40+00:00Added an answer on June 9, 2026 at 2:25 am

    The name lookup was indeed failing, because I didn’t include a name scope and then register the name.

    Correct implementation was to:

    1. Create a name scope for my LayoutControl at instanciation time:

      NameScope.SetNameScope(layoutControl, new NameScope());
      
    2. Register my button’s name:

      public static void InstallItemsInLayoutControl(LayoutControl layoutControl)
      {
          // FAKE TEST VERSION
          Button btn = new Button();
          btn.Name = "TESTBUTTON";
          btn.Content = "Test Me";
          btn.Height = 23;
          btn.Width = 100;
          btn.HorizontalAlignment = HorizontalAlignment.Left;
          btn.VerticalAlignment = VerticalAlignment.Top;
          btn.Width = 100;
          layoutControl.RegisterName(btn.Name, btn);  // THIS LINE WAS MISSING
          layoutControl.Children.Add(btn);
      }
      
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

EDIT I have finally figured out the problem i have been having on my
EDIT: I figured it out from Bergi's answer in the end. Thanks Bergi. pubPrivExample
EDIT: Figured out the problem. Also if you found this through google or another
EDIT: I figured out the solution. I was not adding -combine to my compile
EDIT: I'm sorry for making this thread as I've figured out the problem. Here's
EDIT SO I figured out a fix. I replaced the while statement with an
Edit: I think I've figured out how to do the binary data part. Double
EDIT AGAIN ... I'm just a dummy and figured it out! EDIT: So, it
EDIT: See my answer below--> I am wanting to have a view that when
I've finally figured out how to make all my millions of tabs (not that

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.