Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all articles
Browse latest Browse all 18858

Cloning a WPF UI

$
0
0

Hello

I'm looking to clone a WPF UI. The idea is to divide a UI in half and create two sides that look the same. I am getting the elements from the LogicalTree, but I can't seem to get the properties on each different type of UI Element. 

Is there a simpler way to do this?

private void cloneUI(Panel p)
        {
            //clone grid
            Grid sp = new Grid();
            sp.HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch;
            sp.VerticalAlignment = System.Windows.VerticalAlignment.Stretch;
            sp.Height = Double.NaN;
            Grid.SetColumn(sp, 1);
            this.mainGrid.Children.Add(sp);
            //clone grid

            foreach(UIElement uie in p.Children)
            {

                MessageBox.Show(uie.ToString());
                Type type = uie.GetType();
                if(typeof(Panel).IsAssignableFrom(type))
                {
                    cloneUI(uie as Panel);
                }

                Object obj = Activator.CreateInstance(type);
                sp.Children.Add(obj as FrameworkElement);
            }
        }

This is just for reference to what I'm doing. I've tried several things, including a simple rectangle with a VisualBrush to the top UI element, but I want to shift elements independently in each side, so VisualBrush doesn't cut it for me. Any ideas are appreciated. 

Thanks

diekus


diekus


Viewing all articles
Browse latest Browse all 18858

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>