I am trying to see if the XamlTabControl will work for my application which uses CAL/Prism. It was quite easy to swap in to replace the standard TabControl and all things are function with respect to the visual affect of closing tabs, but I'm having a problem. Close the Tab doesn't remove the View from the Region as one would expect. My question is, has anyone written a Region Adapter for the XamTabControl that supports the close? I know Josh Smith did some work for your controls with Prism, but I haven't been able to locate anything for the Tab control.
Suggestions?
I faced the same issue, and here is my soluction:
Firstly, in the view, disable the build in tab closing button and add the follow button. The button is binded to CloseTabCommand with parameter as the tab control's selected item.
<igWindows:XamTabControl.PostTabItemContent><StackPanel Orientation="Horizontal" HorizontalAlignment="Right">
<Button Command="{Binding CloseTabCommand}" CommandParameter="{Binding ElementName=XamTab, Path=SelectedItem}" IsEnabled="{Binding ElementName=XamTab, Path=HasItems}" Margin="0" ToolTip="Close Current Tab" >Close x</Button></StackPanel></igWindows:XamTabControl.PostTabItemContent>
In ViewModel, define the command. In constructor, attach OnTabClosing method to the command. In the method, remove the selected view from whatever region you defined.
public ICommand CloseTabCommand { get; private set; }// define the command;
CloseTabCommand = new DelegateCommand<object>(OnTabClosing);//In constructor, attach OnTabClosing method to the command
private void OnTabClosing(object obj)
{
if(obj==null) return;
_regionManager.Regions[RegionNames.Main].Remove(obj);
}
There is currently no custom region adapter for the xamTabControl. The close functionality of the xamTabControl doesn't remove the item from its items collection - it just hides the tab so you would need to write your own regionadapter to handle removing the tab items. You may want to submit a suggestion in the discussions of the codeplex project for adding this to NCAL.
Any solutions to this? I am running in to the same problem, and I believe it is the source of a memory leak I am seeing.