How can use ModernTab to add new Tab Like a Browser?

May 28, 2013 at 2:42 PM
Hello Guys,
I m working with WPF; VS2010
i Want to create a User Contol with a ModernTab where i can add some new Tab by clicking on " +" or "NEW".

please i need help!
Ghis from Germany
May 29, 2013 at 6:39 AM
Edited May 29, 2013 at 6:40 AM
Is this what you are looking for?
Coordinator
May 29, 2013 at 10:01 PM
Edited May 29, 2013 at 10:02 PM
The ModernTab doesn't expose events yet, so you need to solve this using a viewmodel, where you need to add a link when the '+' or 'new' link gets selected. Something like this works;
public class MyViewModel : NotifyPropertyChanged
{
  private Link NewLink = new Link {
    DisplayName = "+",
    Source= new Uri("/Pages/EmptyPage.xaml", UriKind.Relative)
  };

  private LinkCollection links = new LinkCollection();
  private Uri selectedSource;

  public HomeViewModel()
  {
    this.links.Add(NewLink);
  }

  public LinkCollection Links
  {
    get { return this.links; }
  }

  public Uri SelectedSource
  {
    get { return this.selectedSource; }
    set
  {
    if (this.selectedSource != value) {
      this.selectedSource = value;
      OnPropertyChanged("SelectedSource");

      if (value == NewLink.Source) {
        // NewLink has been selected, insert a link (right before the last one)
        var i = links.Count;
        var link = new Link() {
          DisplayName = "Link " + i,
          Source = new Uri("/Pages/EmptyPage.xaml?" + i, UriKind.Relative)
        };

        this.links.Insert(links.Count - 1, link);
        this.SelectedSource = link.Source;
      }
    }
  }
}
and your XAML should look like this (assuming DataContext is set to above MyViewModel instance:
<mui:ModernTab
    SelectedSource="{Binding SelectedSource, Mode=TwoWay}"
    Links="{Binding Links}"
    Layout="Tab" />
Please note that in above sample, the /Pages/EmptyPage.xaml needs to exist.
Jun 12, 2013 at 4:30 PM
hi !!
it works!!.. Thank..
I try the same Approch to remove a Tab , but it s not Working !!? why ??
Jun 14, 2013 at 3:29 PM
I got a Solution!!! :D
Mar 30, 2014 at 1:13 PM
Ghis1982 wrote:
I got a Solution!!! :D
Hi

It's been a while, but ... what is the solution? I am trying to do the same (open new tabs and close them) but I cannot figure out how.