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

  • Home
  • SEARCH
  • 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 5996259
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T00:04:40+00:00 2026-05-23T00:04:40+00:00

xaml <controls:TabControl x:Name=tabControlRoom Grid.Row=1 Grid.Column=1 d:LayoutOverrides=Width, Height ItemsSource={Binding} > <controls:TabControl.ItemTemplate> <DataTemplate> <controls:TabItem Header={Binding name}>

  • 0

xaml

<controls:TabControl x:Name="tabControlRoom" Grid.Row="1" Grid.Column="1" d:LayoutOverrides="Width, Height" ItemsSource="{Binding}" >
            <controls:TabControl.ItemTemplate>
                <DataTemplate>
                    <controls:TabItem Header="{Binding name}">
                        <StackPanel Margin="10" Orientation="Horizontal">

                        </StackPanel>
                    </controls:TabItem>
                </DataTemplate>
            </controls:TabControl.ItemTemplate>
        </controls:TabControl>

and code

m_roomContext.Load(m_roomContext.GetRoomQuery());
                tabControlRoom.DataContext = m_roomContext.Rooms;

when I open this page, then there is all the elements, but a second later I see only a white screen

error:

load operation failed for query
‘GetRoom’. Unable to cast object of
type ‘Web.Room’ to type
‘System.Windows.Controls.TabItem’/’

  • 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-23T00:04:41+00:00Added an answer on May 23, 2026 at 12:04 am

    Create converter

    public class SourceToTabItemsConverter : IValueConverter
        {
            public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
            {
                try
                {
                    var source = (IEnumerable)value;
                    if (source != null)
                    {
                        var controlTemplate = (ControlTemplate)parameter;
    
                        var tabItems = new List<TabItem>();
    
                        foreach (object item in source)
                        {
                            PropertyInfo[] propertyInfos = item.GetType().GetProperties();
    
                            //тут мы выбираем, то поле которое будет Header. Вы должны сами вводить это значение.
                            var propertyInfo = propertyInfos.First(x => x.Name == "name");
    
                            string headerText = null;
                            if (propertyInfo != null)
                            {
                                object propValue = propertyInfo.GetValue(item, null);
                                headerText = (propValue ?? string.Empty).ToString();
                            }
    
                            var tabItem = new TabItem
                                              {
                                                  DataContext = item,
                                                  Header = headerText,
                                                  Content =
                                                      controlTemplate == null
                                                          ? item
                                                          : new ContentControl { Template = controlTemplate }
                                              };
    
                            tabItems.Add(tabItem);
                        }
    
                        return tabItems;
                    }
                    return null;
                }
                catch (Exception)
                {
                    return null;
                }
            }
    
            /// <summary>
            /// ConvertBack method is not supported
            /// </summary>
            public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
            {
                throw new NotSupportedException("ConvertBack method is not supported");
            }
    

    Create ControlTemplate:

    <ControlTemplate x:Key="MyTabItemContentTemplate">
                <StackPanel>
                    <TextBlock Text="{Binding Path=name}" />
                </StackPanel>
            </ControlTemplate>
    

    And binding convert, controltemplate

    <controls:TabControl  x:Name="tabControl"
            ItemsSource="{Binding ElementName=tabControl, 
                                  Path=DataContext, 
                                  Converter={StaticResource ConverterCollectionToTabItems}, 
                                  ConverterParameter={StaticResource MyTabItemContentTemplate}}">
            </controls:TabControl>
    

    taken from the blog binding-tabcontrol

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

Sidebar

Related Questions

I have this code in MainPage.xaml: <controls:PivotItem Header=first> <ListBox x:Name=MyListBox Margin=0,0,-12,0 ItemsSource={Binding ListBoxItem}> <ListBox.ItemTemplate>
I have a TabControl region in Shell.xaml: <TabControl Name=TabRegionControl prism:RegionManager.RegionName=TabRegion /> The user can
i have the following code to be implemented into my xaml file. <ItemsControl ItemsSource={Binding
I have a tab content template set to my tab control: <TabControl SelectedIndex=0 ItemsSource={Binding
I have the following XAML: <UserControl x:Class=EMS.Controls.Dictionary.TOCControl xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml xmlns:vm=clr-namespace:EMS.Controls.Dictionary.Models xmlns:diagnostics=clr-namespace:System.Diagnostics;assembly=WindowsBase x:Name=root > <TreeView
I'd like to loop through the controls within a TabItem. my xaml is something
How can I load XAML which is from the DataBase into the grid control
I have a XAML code that should load my UserControl inside the TabControl .
I have the following xaml which resides in a wpf user control - <Grid>
Hi I try solve how stretch user control width / height which is active

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.