Emergency: remove Tab using ModernTab

Jun 6, 2013 at 6:21 AM
My scenario..
I can add a New Tab on ModernTab Programmatically(mvvm) but now i want to close this Tab
How can i do ?

I add in template moderntab after a Textblock one buttom with Content ="x",
and Command={binding RemoveCommand} this can Not return to viewmodel when i click x ? Why?
Any Suggestion??
Ghis from Germany..
Coordinator
Jun 7, 2013 at 5:25 PM
Remove a tab by removing its associated link from the ModernTab.Links link collection (which should be bound to your viewmodel).
Jun 9, 2013 at 9:54 PM
Of cause,
But i want to close the Tab without select it!!..
How can i do that ?
Coordinator
Jun 10, 2013 at 10:37 AM
I see no reason that requires your to select the tab before deleting it
Jun 10, 2013 at 4:47 PM
Hi,
Sorry but i still have trouble with that removeTab.
this my Approch:
from ressoures: x:key="ModernTabStyle"
                        <ListBox.ItemTemplate>
                            <DataTemplate>
                                <StackPanel Orientation="Horizontal">                                       

                                    <TextBlock Text="{Binding DisplayName, Converter={StaticResource ToUpperConverter}}" />
                                    <Button  Command="{Binding RemoveCommand}" Margin="10,0,0,0" Content="X"/>
                                </StackPanel>
                            </DataTemplate>
                        </ListBox.ItemTemplate>


from ViewModel:
//ModernTab
    private LinkCollection _kundenAnzeige= new LinkCollection();
    public LinkCollection KundenAnzeigen
    {
        get { return this._kundenAnzeige; }
        set
        {
            this._kundenAnzeige = value;
            OnPropertyChanged("KundenAnzeigen");
        }

    }
    private Uri _selectedKunde;
    public Uri SelectedKunde
    {
        get { return this._selectedKunde; }
        set
        {

            this._selectedKunde = value;
            if (this._selectedKunde==linkPlus.Source)
            {

                Link link = new Link();
                link.DisplayName = "Link " + KundenAnzeigen.Count;
                link.Source = new Uri("/Views/PersonView.xaml", UriKind.Relative);
                _kundenAnzeige.Insert(_kundenAnzeige.Count - 1, link);
                this._selectedKunde = link.Source;
            }
            OnPropertyChanged("SelectedKunde");
        }

    }
public ICommand RemoveCommand { get; set; }
    private void initCommands()
    {
        RemoveCommand = new RelayCommand(executeRemove, canExecuteRemove);
    }
    private bool canExecuteRemove(object sender)
    {
        return true;
    }
    private void executeRemove(object paramater)
    {
        string charac = paramater.ToString();
        //var neuListe = DbAccess.GetKunden(charac);

    }
}

view:
<mui:ModernTab Style="{DynamicResource ModernTabStyle}" Links="{Binding KundenAnzeigen}"
                      SelectedSource="{Binding SelectedKunde, Mode=TwoWay}"/>
i can t bind the with ViewModel wenn i click on X..
Thanks...
Jun 12, 2013 at 10:31 AM
kowz wrote:
Remove a tab by removing its associated link from the ModernTab.Links link collection (which should be bound to your viewmodel).

yes !! sir .. i got a link collection as KundenAnzeigen, and i bound this with property Links.. this is not working ...!!! why?
Jun 12, 2013 at 10:42 AM
Edited Jun 12, 2013 at 10:45 AM
this line
_kundenAnzeige.Insert(_kundenAnzeige.Count - 1, link);
wont trigger the OnPropertyChanged("KundenAnzeigen"); because it bypasses the setter method. Therefore the SelectedSource Binding is not notifyed about the change.

Replace the line mentioned above by this one:
this.KundenAnzeige.Insert(this.KundenAnzeige.Count - 1, link);
Greetings from Germany,
Xenolith
Jun 12, 2013 at 3:55 PM
Hello Xenolith!!
First wort i appreciate Ur Help...
for adding a tab, this is working fine... But i want to remove this after added!!! i mean with a Command Like relayCommand in VM..
any Idee??

my approch : I replace the template like this

<ListBox.ItemTemplate>
                            <DataTemplate>
                                <StackPanel Orientation="Horizontal">                                        
                                  <TextBlock Text="{Binding DisplayName, Converter={StaticResource ToUpperConverter}}" />
                                    <Button Content="x"  Command ="{Binding Path=RemoveCommand}"Style="{DynamicResource ResourceKey=SystemButtonLink}" />
                                </StackPanel>
                            </DataTemplate>
                        </ListBox.ItemTemplate>
my Goad is: i wan to jump to execudeRemove_methode wenn i click on Button " x"...
Help ..
Best regard from Mainz City (Germany)
Jun 13, 2013 at 8:43 AM
i use this code to remove a group from the main menu, not sure if it works also for the tab control.
        private LinkGroupCollection menuLinkGroups;
        public LinkGroupCollection MenuLinkGroups
        {
            get { return this.menuLinkGroups; }
            set
            {
                this.menuLinkGroups = value;
                this.OnPropertyChanged("MenuLinkGroups");
            }
        }

        private void RemoveGroupFromMenu()
        {
                if (this.MenuLinkGroups.Count > 5 && this.MenuLinkGroups[5].DisplayName.Equals("YourMenuGroupNameHere"))
                {
                    this.MenuLinkGroups.RemoveAt(5);
                }
        }