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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T06:33:01+00:00 2026-05-30T06:33:01+00:00

So I want to have multiple tabs with a usercontrol in it, depending on

  • 0

So I want to have multiple tabs with a usercontrol in it, depending on how many items there are in a list. so I think this shoudn t be too hard but …. I start with a new window to make a tabcontroller and bind its itemsource(of the tabcontroler to the list):

<Window x:Class="xxxxx.extraforms.frmownedchamps"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
               xmlns:sp="clr-xxxxx.usercontrols.ucoptions"
        Title="frmownedchamps" Height="593" Width="350" Loaded="Window_Loaded_1" ResizeMode="NoResize" WindowStyle="None" ShowInTaskbar="False">
    <Grid>
        <TabControl Name="thetabcontrol">
            <TabControl.ItemTemplate>
                <DataTemplate>

                    <StackPanel>
                        <Label  Content="{Binding name}" />
                    </StackPanel>

                </DataTemplate>
            </TabControl.ItemTemplate>

            <TabControl.ContentTemplate>
                <DataTemplate DataType="{x:Type sp:ucownedchampviewer}" >
                    <sp:ucownedchampviewer strname="{Binding Path=name}" strcode="{Binding Path=code}" clclist="{Binding Path=list}" teller="{Binding Path=teller}"  />
                </DataTemplate>
            </TabControl.ContentTemplate>
        </TabControl>

    </Grid>
</Window>

once the window get loaded it only does thetabcontrol.ItemsSource = settings.clclist;

the clclist is this:

     public static List<clc> clclist { get; set; }

    public void methodblabla()
    {
     foreach( xml blabla)
    {
    clc clctemp = new clc(xmlname, xmlcode);
    clclist.Add(clctemp);
    }
    }

the clc class is:

 public class clc
        {
            private static int counter = 0;
            public int teller { get; set; }
            public String name { get; set; }
            public String code { get; set; }
            public ObservableCollection<champion> list { get; set; }
            public clc(String name, String code)
            {

                this.name = name;
                this.code = code;
                teller = counter;
                counter++;
                makelist();
            }
            public void makelist()
            {
                var bytes = Convert.FromBase64String(code);
                var values = new System.Collections.BitArray(bytes);
                list = new ObservableCollection<champion>();
                int aantal = champions.list.Count;
                int teller = 0;
                int counter = 0;
                for (int x = aantal; x != 0; x--)
                {
                    if (values[x - 1] == true)
                    {
                        list.Add(champions.getchampbyid(counter + 1));
                        teller++;
                    }
                    counter++;
                }
            }
        }  

my usercontrol:

<UserControl x:Class="xxxxx.usercontrols.ucoptions.ucownedchampviewer"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
              xmlns:sp="clr-namespace:xxxxx"
             mc:Ignorable="d" 
             d:DesignHeight="564" d:DesignWidth="350" Loaded="UserControl_Loaded">
    <Grid Height="624">
        <Grid.Resources>
            <Style x:Key="Ownedstyle" TargetType="{x:Type ListViewItem}">
                <Setter Property="Background" Value="Red"></Setter>
                <Style.Triggers>
                    <DataTrigger Binding="{Binding strowned}" Value="Yes">
                        <Setter Property="Background" Value="Green"></Setter>
                    </DataTrigger>
                </Style.Triggers>
            </Style>
        </Grid.Resources>
            <StackPanel Margin="0,0,0,12">
            <StackPanel Orientation="Horizontal" Margin="5">
                <TextBox Name="txtclc" Width="250" Margin="2" Text="{Binding Path=strcode ,RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}}" />
                <Button Name="btnload" Content="Save" Click="btnsave_Click" Width="55" Margin="2"/>
            </StackPanel>
            <Line Margin="2" />
            <StackPanel Orientation="Horizontal" Margin="5" HorizontalAlignment="Stretch" Width="350">
                <TextBlock VerticalAlignment="Center">Filter:</TextBlock>
                <TextBox Name="txtfilter" Height="30" Grid.Column="0" TextChanged="txtfilter_TextChanged" Margin="5" Width="250" />
                <Label Name="lblaantal"></Label>
            </StackPanel>
            <ListView Name="lsvallchamps"  Grid.Column="0" Grid.Row="1" Grid.RowSpan="1" Height="410" Width="auto" ItemContainerStyle="{StaticResource Ownedstyle}" ItemsSource="{Binding Path=clclist ,RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}}" >
                <ListView.View>
                    <GridView>
                        <GridViewColumn Width="60">
                            <GridViewColumn.CellTemplate>
                                <DataTemplate>
                                    <Image HorizontalAlignment="Center" VerticalAlignment="Center" Width="50" Height="50" Source="{Binding image}" Stretch="Fill"></Image>
                                </DataTemplate>
                            </GridViewColumn.CellTemplate>
                        </GridViewColumn>
                        <GridViewColumn Width="120" DisplayMemberBinding="{Binding name}">
                            <GridViewColumnHeader Content="name" Tag="name" Click="SortClick"/>
                        </GridViewColumn>
                        <GridViewColumn Width="130" DisplayMemberBinding="{Binding strroles}">
                            <GridViewColumnHeader Content="strroles" Tag="strroles" Click="SortClick" />
                        </GridViewColumn>
                    </GridView>
                </ListView.View>
            </ListView>
            <Button Content="testknop" Click="Button_Click" />
            <Button Content="Hide" Name="btnhide" Width="150" Height="35" Margin="5" Click="btnhide_Click"></Button>
        </StackPanel>
    </Grid>
</UserControl>

Sorry for so much code, but mayby better too much then too less code. The problem is that I want the button btnsave to save the txtclc.text to the code and make a new list of it, (and then the listview should be automaticly changed according to it since it is binded to it)
However once I use the code

   private void btnsave_Click(object sender, RoutedEventArgs e)
        {
            settings.clclist[teller].code = txtclc.Text;
            settings.clclist[teller].makelist();
        }

It does change it! I can see it with debug.writeline that the value has changed in the clclist. BUT the listview in this tab doesn t change! ONLY if I go to an other tab, then back to the first one then it has changed with the right champions. There even is a 2nd problem. O But if I go to an other tab(usercontrol) the txtclc.text is changed as well to the first one! also the list is not updated on the usercontrol, on neither! however the makelist method should change it?
Sorry for this LONG question however I ve been googeling alot and no luck for this problem.

SOLUTION:

Replace Text=”{Binding Path=strcode ,RelativeSource={RelativeSource AncestorType={x:Type UserControl}}}” with Text=”{Binding Path=code}” in the usercontrol. and add INotifyPropertyChanged to the clc class, Thx to Rachel!

  • 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-30T06:33:03+00:00Added an answer on May 30, 2026 at 6:33 am

    You have two problems here.

    The first, is that your classes don’t implement INotifyPropertyChanged, so the UI has no idea that it’s objects have changed. Make your clc class implement this interface, and raise the PropertyChanged event when the code and name properties change so the UI knows to update.

    The second problem is that by default, WPF will re-use a template if possible. For example, your TabControl is creating one instance of your UserControl, and when you switch tabs it is simply changing the DataContext behind the UserControl. If txtclc.Text is not bound to something in the DataContext, then it will not change because you are viewing the exact same TextBox regardless of which tab you are viewing. The solution is to add a property to your DataContext object to store the Text of the txtclc TextBox, and bind the property.

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

Sidebar

Related Questions

i have a table view containing multiple tabs, on this tabs i want to
I have a data base in which multiple items are there.And also I have
I have a program wherein there are multiple tabs added dynamically to a TabControl
I want to have multiple launcher icons for my application. I can get this
I want to have a tree in memory, where each node can have multiple
We have multiple vb projects.We want to put error handlers in all functions, and
I have multiple SharePoint lists and want to display data from them on to
I have multiple excel files which I open as datatable I want to merge
I have multiple document.ready functions on a page and I want a function to
I have multiple (8) WAR files and 1 EAR file that I want to

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.