Problem With Navigating To Existing Links

Sep 10, 2013 at 11:26 AM
Hi I'm New here and love this project but I'm really struggling trying to understand the Navigation side of this.

My Problem is this:

I have a DataGrid and when I doubleclick a row a new Link is added called "Ticket " + Cell[0] this works fine.
When I select this new Link it is bound to a User Control which uses the ModernTab page again this Displays Correctly.

however I wish to populate these fields with information from a SQL DB based on the Ticket Number (Cell[0]) the problem I have here is when I have multiple new links I can find no way to identify the newely created Link so I cant bind this new ModernTab to a Datasource.

My Question is.

All I really want to do is be able to get a list of all available Links that have been created so I can do something like this:

MenuName = Cells[0]
        foreach (Window link in ModernFrame.Source)
        }            }
so in short I just want to know what the page source/s link name is?

Please help its driving me mad!!
Sep 10, 2013 at 1:40 PM
ModernTab holds all the links as a LinkCollection you can access this collection with the following notation.
Sep 10, 2013 at 2:07 PM
Thank you Melvinchi,

Unfortunately I'm finding it difficult to understand how to use this Collection can you please provide an example?

I would just like to check through the entire collections Display Names so I can discover if a Link with the same name exists if so I need to do 'Something' with this.


the above image displays the following:

1 = The Created Dynamic Link
2 = a Copy of the Ticket Number (just testing at the moment)
__3 = the Button!!
when I press the Button (3) I want to loop through all items in the list below [OPEN TAB(S)]

Sorry to be a pain any help appreciated

Sep 10, 2013 at 8:27 PM
You may want to store your links in a viewmodel and bind the ModernTab.Links to them. In your viewmodel you can iterate the links.

Your viewmodel:
public class ViewModel
  : NotifyPropertyChanged
  private LinkCollection links = new LinkCollection();
  private Uri selectedSource;

  public LinkCollection Links
    get { return this.links; }

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

  public void AddLink(int ticketNumber)
    // add new link
    var source = new Uri("/TicketPage?" + ticketNumber", UriKind.Relative)

    this.links.Add(new Link {
      DisplayName = "Ticket " + tickNumber, 
      Source = source;

    // and select the link
    this.SelectedSource = source;

  public void HandleButtonClick()
    foreach(var link in this.links) {
      // do something with each dynamic link
Your view xaml (assuming the ViewModel is assigned to the DataContext of the ModernTab (or any of its ancestors)
<mui:ModernTab Layout="List" Links="{Binding Links}" SelectedSource="{Binding SelectedSource, Mode=TwoWay}" />
And finally, not sure whether your 'my ticket', 'create ticket', 'search ticket' options should be in the list, they sound like commands to me and it may be better to move them to some sort ModernButton toolbar?
Sep 11, 2013 at 12:15 PM
Kozw your a star! thank you so much it took me a while to understand how to utilize this but I think I have it again thank you so much for all your help :-)
Sep 11, 2013 at 1:26 PM
@Brett1981 Glad you got it squared away. I only check this about once a day here and there if I run into problems :D

Kozw is a star!
Sep 11, 2013 at 1:49 PM
<mui:ModernTab Layout="List" Links="{Binding Links}" SelectedSource="{Binding SelectedSource, Mode=TwoWay}" />
Melvinchi - I know what you mean but im on here about 20 times a day (still learning you see :-))

Kozw - Im a little confused to be honest I get 98% of what you have suggested but I just have a small problem and not sure what to do here:
on my List Page I have the following Code:
<UserControl x:Name="TicketList" x:Class="SIDE.Views.TicketLists"
             d:DesignHeight="300" d:DesignWidth="300">
    <Grid Style="{StaticResource ContentRoot}" Margin="16,16,16,16">
        <!-- TODO: set @SelectedSource -->
        <mui:ModernTab Layout="List" SelectedSource="\Views\Home.xaml">
                <!-- TODO: set @Source -->
                <mui:Link DisplayName="My Tickets" Source="\Views\Home.xaml" />
                <mui:Link DisplayName="Create Ticket" Source="\Views\PageTicket.xaml" />
                <mui:Link DisplayName="Team Tickets" />
                <mui:Link DisplayName="Performance" />
                <mui:Link DisplayName=" " />
                <mui:Link DisplayName="Search Ticket" />
                <mui:Link DisplayName=" " />
                <mui:Link DisplayName="Exit" />
                <mui:Link DisplayName="________________________________" />

                <mui:Link DisplayName="Open Tab(s)" />


        <!-- <mui:ModernTab Layout="List" Links="{Binding Links}" SelectedSource="{Binding SelectedSource, Mode=TwoWay}" />-->
Going by what your suggesting I can't add the Links="{Binding Links} because im already using mui:Link for static links as above.

If I understand correctly I should change my <mui:ModerTab></mui:ModernTab> to what you suggested and then on opening this User Control populate the tabs from the ViewModel?

Am I confused or just stupid? or both if you prefer.. Thanks again in advance
Sep 11, 2013 at 1:58 PM
Just to add to this:

Prior to using your Example of the viewmodel this is how I added the dynamic link
        private void MainTicketsGrid_MouseDoubleClick(object sender, MouseButtonEventArgs e)

            DataRecord activeRecord = (MainTicketsGrid.ActiveRecord as DataRecord);
            string names = "";
                if ((activeRecord != null) && (!activeRecord.IsAddRecord))
                    ModernTab parentMT = new ModernTab();
                    // this <- your current child

                        parentMT =
                        ((Grid)((SIDE.ModernUI.Windows.Controls.ModernFrame)this.Parent).Parent).TemplatedParent as ModernTab;
                        parentMT.Links.Add(new Link
                            DisplayName = string.Format(CultureInfo.InvariantCulture, "Ticket {0}", activeRecord.Cells[0].ConvertedValue.ToString()),
                            Source = new Uri(string.Format(CultureInfo.InvariantCulture, "/Views/PageTicket.xaml?{0}", activeRecord.Cells[0].ConvertedValue.ToString()), UriKind.Relative),

                    int LinkCount = 0;

                    LinkCount = parentMT.Links.Count - 1;


                    names = parentMT.Links[LinkCount].DisplayName.ToString();
                    var result = names.Substring(names.LastIndexOf(' ') + 1);
                    GlobalAtt.strticketNumber = result.ToString();