Hi
I have a xamTabControl whose ItemsSource is bound to an observable collection of viewmodels and need to have editable tab headers. I am using the example found here:
http://blogs.infragistics.com/blogs/alex_fidanov/archive/2009/10/01/how-to-rename-the-tabitems-of-the-xamtabcontrol-runtime-like-excel.aspx
But the problem is that instead of the Header property, the object type ToString() is being displayed in the tab header. Any idea what I might have done wrong and how I can get the actual header property displayed?
In my view I have the following (along with the TabItemEx style specified above):
<ig:XamTabControl ItemsSource="{Binding WorkspaceTabNames}" TabStripPlacement="Bottom" ContentTemplate="{StaticResource tabContentDataTemplate}" Theme="Office2k7Blue">
Tried to modify the style of TabItemEx slightly to this:
<igEditors:XamTextEditor PreviewMouseLeftButtonDown="tbEdit_PreviewMouseDoubleClick" BorderThickness="0" Background="Transparent" EditModeStarting="tbEdit_EditModeStarting" EditModeEnding="tbEdit_EditModeEnding" Value="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Header, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>
In the view model of my view containing the tab control:
public ObservableCollection<WorkspaceViewModel> WorkspaceTabNames{ get { return new ObservableCollection<WorkspaceViewModel> { new WorkspaceViewModel("Tab 1", "Content 1"), new WorkspaceViewModel("Tab 2", "Content 2"), new WorkspaceViewModel("Tab x", "Content x") }; }}
And finally, the view model itself:
public class WorkspaceViewModel: INotifyPropertyChanged{ public string Header { get; private set; } public string Content { get; private set; }
public WorkspaceViewModel(string header, string content) { Header = header; Content = content; }
#region INotifyPropertyChanged Implementation ... #endregion}
I see a number of problems. First, you are setting the ContentTemplate. The ContentTemplate of a TabControl affects what is showing the content - i.e. the main body of the tab control and not the header of the tab item. You would want to set the ItemTemplate which is what affects the content of the items created by an items control (TabItemEx in this case). Second you are using TemplatedParent as a relativesource for the binding but the templated parent of something within a DataTemplate is the ContentPresenter that uses the DataTemplate and even then it doesn't have a Header property - the DataContext does so you need to remove the RelativeSource from that binding. Third, the Header property has a private setter - if you want to be able to update that then it needs to be public. So something like this:
<Grid xmlns:igWindows="http://infragistics.com/Windows" xmlns:igEditors="http://infragistics.com/Editors"> <Grid.Resources> <DataTemplate x:Key="tabContentDataTemplate"> <igEditors:XamTextEditor BorderThickness="0" Background="Transparent" Value="{Binding Path=Header, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/> </DataTemplate> </Grid.Resources> <igWindows:XamTabControl ItemsSource="{Binding WorkspaceTabNames}" TabStripPlacement="Bottom" ItemTemplate="{StaticResource tabContentDataTemplate}" Theme="Office2k7Blue"/> </Grid>
Thanks for your reply but I don't think that was the issue. The editability of the tab is handled by a style (which is in the example link) and not in a DataTemplate.
I got around this by using CAL and adding the views to the xamTabControl region instead of binding my list of viewmodels to the ItemSource of the xamTabControl. Still not sure why this approach worked but for now I do not really have the time to investigate further :-)
Hello,
Thank you for your feedback. I am glad that you resolved your issue and I believe that other community members may benefit from this as well.
Thanks again.
Hi Stefan,
I have a problem in using XamTabControl. I have a XamTabControl whose ItemSource is bound to ObservableCollection of viewmodels.
The View contains a XamDataTree. So I could display the XamDataTree on all the opened tabs of XamTabControl.
But I state of the XamDataTree(Expanded and selected nodes) is not being restored when I switch between tabitems.
The XamDataTree is being collapsed as I traverse between various tabs. Could you please help me in getting a work around for this issue.
thankyou,
Prasanti
Hello Prasanti,
Thank you for your post. I have been looking into it and I can say that when you switch the tabs, the controls inside them unload and load and this is why the expanded state is not preserved. The thing you can do is add an IsExpanded Property to your data and set it to the IsSelectedMemberPath property to the XamDataTree. Here a similar topic is already discussed:
http://ko.infragistics.com/community/forums/p/90631/447829.aspx
Could you please send us an isolated sample project, where this is reproduced, so we could be able to investigate it further for you?
Looking forward for your reply.
Dear Stefan,
Thankyou for your response. I have tried IsExpandedMemberPath and IsSelectedMemberPath as it is stated in the example.
But I could restore only the expanded structure of the XamDataTree but not the selected node of the XamDataTree, on changing the tabs
of XamTabControl. Please help me out.
Thankyou,
Prasanti.