Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
70
TabControl Close button with CAL/Prism Regions
posted

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?

Parents
No Data
Reply
  • 170
    Suggested Answer
    posted

    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);

     }

Children
No Data