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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T14:40:46+00:00 2026-05-12T14:40:46+00:00

Ok, here’s my simple scenario. I’ve got collection of strings that I’m binding to

  • 0

Ok, here’s my simple scenario. I’ve got collection of strings that I’m binding to a TabControl as a proof of concept. As I add strings I want a new tab with the region name as the header and a ItemsControl in the Tab container. That ItemsControl should define a new region.

        <TabControl  x:Name="tabDemo" ItemsSource="{Binding DynamicRegions}" >
        <TabControl.ItemTemplate>
            <DataTemplate>
                <TextBlock Text="{Binding}" />
            </DataTemplate>
        </TabControl.ItemTemplate>
        <TabControl.ContentTemplate>
            <DataTemplate>
                <ItemsControl cal:RegionManager.RegionName="{Binding}" ItemsSource="{x:Null}">

                </ItemsControl>
            </DataTemplate>
        </TabControl.ContentTemplate>
    </TabControl>

From there I add strings to the collection. The tabs show up fine, but when I try to call

   private void AddDynamicRegion(object arg)
  {
     var newRegionName = "Region" + (DynamicRegions.Count + 1).ToString();
     DynamicRegions.Add(newRegionName);
  }

  private void AddRandomRegionContent(object arg)
  {
     if (string.IsNullOrEmpty(SelectedRegion) )
        return; 

     Debug.WriteLine("Injected "  + RegionContent + " into " + SelectedRegion);

     var newContent = new TextBlock() { Text = RegionContent };
     _regionManager.RegisterViewWithRegion(SelectedRegion,() => newContent );

     _regionManager.Regions[SelectedRegion].Activate(newContent);
  }

It either throws an exception that the region doesn’t exist or an exception that creating the region failed and my ItemsControl.ItemsSource is already set. I didn’t really expect this to work out of the box, but is there any way I can create dynamic regions and inject into them at run time?

Update: Calling RegisterViewWithRegion actually injects my textblock…but getting some weird behavior between tabs.

I changed it so I can choose the region and text I want to inject. It always works for the first region I create, but after that, flipping between tabs just shows the stuff I’ve added to the first region. Is the tab control re-using my datatemplate across multiple tabs? I’ve included all my code from the ViewModel. DynamicRegions is just an ObservableCollection

  • 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-12T14:40:47+00:00Added an answer on May 12, 2026 at 2:40 pm

    Ok, I’ve got something that works, but I’d like to see what Anderson Imes comes up with.

    Basically, I set all the region stuff in code when my tabItems are generated using databinding.

      private void AddDynamicRegion(object arg)
      {
         var newRegionName = "Region" + (DynamicRegions.Count + 1).ToString();
         DynamicRegions.Add(newRegionName);
    
         var tabItem = View.tabDemo.ItemContainerGenerator.ContainerFromIndex(DynamicRegions.Count - 1) as TabItem;
         var newRegionContainer = new ItemsControl();
         RegionManager.SetRegionName(newRegionContainer,newRegionName);
         RegionManager.SetRegionManager(newRegionContainer, _regionManager);
         tabItem.Content = newRegionContainer;
    
    
      }
    

    So then in insert I can just do this, and everything shows up under the correct region. I wonder if there is a better way to do it though.

      private void AddRandomRegionContent(object arg)
      {
    
         if (string.IsNullOrEmpty(SelectedRegion) )
            return; 
    
         Debug.WriteLine("Injected "  + RegionContent + " into " + SelectedRegion);
    
         var newContent = new TextBlock() { Text = RegionContent };
         var region = _regionManager.Regions[SelectedRegion];
         if (region == null)
         {
            Debug.WriteLine("Couldn't find region");
            return;
         }
    
         region.Add(newContent);
         region.Activate(newContent);
    
      }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is a scenario: User installs .NET application that you have made. After some
Here is my scenario. I have a website running under AppPool1 and that works
Here is my problem.. I have the option to create(add) two new input fields,
Here's the scenario: I have a local git repository that mirrors the contents of
Here's the situation, i want to have a user that can enter time on
Here is the scenario. I'm writing my geo-ruby oracle adapter for Ruby On Rails
Here's the setup - I have a view that lists products. On that same
Here's my situation. I have a DotNetNuke application. I want to link to an
Here's a sample of a SpinBox that writes its changes to underlying variables. The
Here's the code require_once 'functions.php'; require_once 'cfg.php'; $mysqli = new mysqli($dbhost, $dbuser, $dbpass, $db);

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.