locked
TabControl with TabItem generated using the ITemSource RRS feed

  • Question

  • Hi

    I am facing a problem with WPF's TABControl. I have bind my tabcontrol to the observablecollection of TabData objects (Tabdata contains three properties regionname, name and headername)

    what I want to achieve is that after binding, I should get the tabs equal to number of items in my collection and each tab should have one PRISM region in it with regionname binded to regionname property of tabdata.

    I am able to achieve the following things -

    bind collection to tabcontrol. this generates the tabs as per the count of item in collection.

    But I am not able to get the individual content for each tab item. the binding process is generating the same content (actually only one) for all the tabs.

    <TabControl Grid.Row="1" Grid.RowSpan="2" HorizontalAlignment="Left" Name="tabControl1" ItemsSource="{Binding Path=Tabs}">
    			<TabControl.ItemTemplate>
    				<DataTemplate>
    					<TextBlock Text="{Binding Path=Header}"/>
    				</DataTemplate>
    			</TabControl.ItemTemplate>
    			<TabControl.ContentTemplate>
    				<DataTemplate x:Shared="False" >
    							<ContentControl prism:RegionManager.RegionManager="{Binding RegionManager}" prism:RegionManager.RegionName="{Binding Path=RegionName}"/>
    									</DataTemplate>
    			</TabControl.ContentTemplate>
    		</TabControl>


    Pravin Chandankhede

    Thursday, June 7, 2012 1:12 PM

Answers

  • Hi Pravin Chandankhede,

    This is the default behavior of WPF TabControl, TabContorl could show only one tabItem, could load only one tabitem, we could not get other invisible tabitem's content.

    best regards,


    Sheldon _Xiao[MSFT]
    MSDN Community Support | Feedback to us
    Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Sheldon _Xiao Monday, June 18, 2012 8:39 AM
    Monday, June 11, 2012 8:46 AM

All replies

  • Hi,

    Maybe you just mistyped the property names. I tried the below XAML and code and worked fine for me:

    <TabControl Name="tabControl1">
        <TabControl.ItemTemplate>
            <DataTemplate>
                <TextBlock Text="{Binding Path=HeaderName}" />
            </DataTemplate>
        </TabControl.ItemTemplate>
        <TabControl.ContentTemplate>
            <DataTemplate>
                <StackPanel>
                    <TextBlock Text="{Binding Path=Name}" />
                    <TextBlock Text="{Binding Path=RegionName}" />
                </StackPanel>
            </DataTemplate>
        </TabControl.ContentTemplate>
    </TabControl>
    
    ObservableCollection<TabData> tabs = new ObservableCollection<TabData>();
    tabs.Add(new TabData { HeaderName = "Header1", Name = "Name1", RegionName = "Region1" });
    tabs.Add(new TabData { HeaderName = "Header2", Name = "Name2", RegionName = "Region2" });
    tabs.Add(new TabData { HeaderName = "Header3", Name = "Name3", RegionName = "Region3" });
    
    tabControl1.ItemsSource = tabs;
    

    Thursday, June 7, 2012 1:30 PM
  • Hi Pravin Chandankhede,

    How about your issue?

    Best regards,


    Sheldon _Xiao[MSFT]
    MSDN Community Support | Feedback to us
    Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Friday, June 8, 2012 6:41 AM
  • Hi

    I think I need to explain my problem in more detail. What I am looking for is in the TabControl.ControlTemplate, I was to a have TabItem which will host a ContentControl and this content control is designated as one of the region in terms of PRISM.

    As posted by originally, the <TabControl.ControlTemplate> tag is generating only a single tabitem which has only one region. But I need to have as many tabitem(with PRISM region inside it) as tabs in the tab control.

    Please help in solving this as its very important and urgent for me. I am also open to other soultion if this might not be feasible or suggested method to achieve what I want to. Thanks


    Pravin Chandankhede

    Saturday, June 9, 2012 7:54 AM
  • Hi Pravin Chandankhede,

    This is the default behavior of WPF TabControl, TabContorl could show only one tabItem, could load only one tabitem, we could not get other invisible tabitem's content.

    best regards,


    Sheldon _Xiao[MSFT]
    MSDN Community Support | Feedback to us
    Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Sheldon _Xiao Monday, June 18, 2012 8:39 AM
    Monday, June 11, 2012 8:46 AM
  • Hi Pravin Chandankhede,
     
    I am marking your issue as "Answered", if you have new findings about your issue, please let me know.


    Best regards,


    Sheldon _Xiao[MSFT]
    MSDN Community Support | Feedback to us
    Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, June 18, 2012 8:39 AM