CloseButton and Caption on TabControl

Topics: Prism v2 - WPF 3.5
Dec 24, 2009 at 6:12 PM
hI, I am trying to display a TabItem with text and a close button. I have the following XAML which displays the close button on the TabItem, but for some reason, does not show the text which I have bound to it using: <ContentPresenter Content="{Binding Path=DisplayName}" VerticalAlignment="Center" /> I cannot figure out what's wrong. The TabItem template declared like this: <DataTemplate x:Key="ClosableTabItemTemplate"> <DockPanel Width="120"> <Button Command="{Binding Path=CloseCommand}" Content="X" Cursor="Hand" DockPanel.Dock="Right" Focusable="False" FontFamily="Courier" FontSize="9" FontWeight="Bold" Margin="0,1,0,0" Padding="0" VerticalContentAlignment="Bottom" Width="16" Height="16" /> <ContentPresenter Content="{Binding Path=DisplayName}" VerticalAlignment="Center" /> </DockPanel> </DataTemplate> I have declared the Main region thus: <!-- Main Region --> <Border Margin="2,2,8,8" Grid.Column="2" Grid.Row="2" BorderThickness="2,2,2,2" CornerRadius="4,4,4,4" BorderBrush="#FF929D31" Grid.RowSpan="2"> <!--<ContentControl x:Name="MainRegion" prismrgn:RegionManager.RegionName="MainRegion" Style="{StaticResource ContentControlRegionStyle}" VerticalContentAlignment="Stretch" HorizontalContentAlignment="Stretch"/>--> <TabControl x:Name="MainRegion" prismrgn:RegionManager.RegionName="MainRegion" Width="Auto" Height="Auto" Margin="10,10,0,0" HorizontalAlignment="Stretch" IsSynchronizedWithCurrentItem="True" ItemTemplate="{StaticResource ClosableTabItemTemplate}" /> </Border> DisplayName is a public property declared in the ViewModelBaseClass public abstract class ViewModelBase : DependencyObject, IDataErrorInfo, INotifyPropertyChanged { private string _DisplayName; public virtual string DisplayName { get { return _DisplayName; } set { if (_DisplayName != value) { _DisplayName = value; OnPropertyChanged(this, "DisplayName"); } } } . . . . Any idea on how to solve this problem? Thanks, Arun
Dec 26, 2009 at 4:30 PM

There is a great example on doing this CAL way at StackOverflow.

Dec 26, 2009 at 11:23 PM
highel wrote:

There is a great example on doing this CAL way at StackOverflow.

Thanks for the link. Got it working.