0

I Used Modern UI for WPF and use this library.

From menu link group I used this :

<mui:ModernWindow x:Class="SKBPK2014.MainWindow"

    ContentSource="/UI/Pages/Home.xaml">

   <mui:ModernWindow.MenuLinkGroups>
    <mui:LinkGroup DisplayName="Sampel">
        <mui:LinkGroup.Links>
            <mui:Link DisplayName="HOME" Source="/UI/Pages/Home.xaml" />
            <mui:Link DisplayName="DAFTAR SAMPEL" Source="/UI/Kuesioner/DaftarSampel.xaml" />
        </mui:LinkGroup.Links>
    </mui:LinkGroup>

How to get All UI control in a list in the first load. Not clicking the mui:Link. ? I wanna get like this

List<UIControl> UiControl;

it will contains all UIControl in My ModernWindow. so it will contains {Home,DaftarSampel,} object List in the first load..

Saghir A. Khatri
  • 3,429
  • 6
  • 45
  • 76
mrhands
  • 1,473
  • 4
  • 22
  • 41

2 Answers2

0

Have you considered using an IoC container like Unity or Autofac? You could register all of your control classes as singleton instances in the container, and then you could get references to them from the container on first load.

Mark Richman
  • 28,948
  • 25
  • 99
  • 159
0

I'm not sure of what is your final goal, but I will give you a hint. You can get the visual (or logical) items in you window tree, that match some condition you want. For that propose you can use this methods:

For the visual items:

        public static IEnumerable<DependencyObject> GetVisualChild(DependencyObject item, Func<DependencyObject, bool> condition)
        {
            if (item == null)
                return;

            var q = new Queue<DependencyObject>();
            for (int i = 0; i < VisualTreeHelper.GetChildrenCount(item); i++)
            {
                var t = VisualTreeHelper.GetChild(item, i);
                if (condition(t))
                    yield return t;
                q.Enqueue(t);
            }

            while (q.Count > 0)
            {
                var subchild = q.Dequeue();
                for (int i = 0; i < VisualTreeHelper.GetChildrenCount(subchild); i++)
                {
                    var t = VisualTreeHelper.GetChild(subchild, i);
                    if (condition(t))
                        yield return t;
                    q.Enqueue(t);
                }
            }
            return null;
        }

For the Logical Items

public static IEnumerable<DependencyObject> GetLogicalChild(DependencyObject item, Func<DependencyObject, bool> condition)
    {
        if (item == null)
            return;

        var q = new Queue<DependencyObject>();
        foreach (var w in LogicalTreeHelper.GetChildren(item))
        {
            var t = w as DependencyObject;
            if (condition(t))
                yield return t;
            q.Enqueue(t);
        }

        while (q.Count > 0)
        {
            var subchild = q.Dequeue();
            foreach (var w in LogicalTreeHelper.GetChildren(subchild))
            {
                var t = w as DependencyObject;
                if (condition(t))
                    yield return t;
                q.Enqueue(t);
            }
        }
        return null;
    }

If you want to control the logic, you should to implement the Mvvm pattern. Hope my tips helps...

Raúl Otaño
  • 4,640
  • 3
  • 31
  • 65