Add a Polyline to the StackPanel : StackPanel « Windows Presentation Foundation « C# / CSharp Tutorial






using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

    public class MainClass : Window
    {
        [STAThread]
        public static void Main()
        {
            Application app = new Application();
            app.Run(new MainClass());
        }
        public MainClass()
        {
            Button btn = new Button();
            btn.HorizontalAlignment = HorizontalAlignment.Center;
            btn.VerticalAlignment = VerticalAlignment.Center;
            btn.Click += ButtonOnClick;
            Content = btn;

            StackPanel stack = new StackPanel();
            btn.Content = stack;

            Polyline poly = new Polyline();
            poly.Stroke = SystemColors.ControlTextBrush;
            poly.Points = new PointCollection();
            for (int x = 0; x <= 100; x += 10)
                poly.Points.Add(new Point(x, (x + 10) % 20));
            
            stack.Children.Add(poly);

            Uri uri = new Uri("pack://application:,,/BOOK06.ICO");  // 32-pixels
            BitmapImage bitmap = new BitmapImage(uri);
            Image img = new Image();
            img.Margin = new Thickness(0, 10, 0, 0);
            img.Source = bitmap;
            img.Stretch = Stretch.None;
            stack.Children.Add(img);
        }
        void ButtonOnClick(object sender, RoutedEventArgs args)
        {
            MessageBox.Show("The button has been clicked", Title);
        }
    }








24.56.StackPanel
24.56.1.Stretch = UniformStretch = Uniform
24.56.2.Stretch = UniformToFillStretch = UniformToFill
24.56.3.Stretch = FillStretch = Fill
24.56.4.Stretch = NoneStretch = None
24.56.5.StackPanel with StackPanelStackPanel with StackPanel
24.56.6.Simple StackPanelSimple StackPanel
24.56.7.Set height, Background and Orientation for StackPanelSet height, Background and Orientation for StackPanel
24.56.8.Change StackPanel OrientationChange StackPanel Orientation
24.56.9.Use the methods that are defined by the IScrollInfo interface to scroll the child content of a StackPanel.Use the methods that are defined by the IScrollInfo interface to scroll the child content of a StackPanel.
24.56.10.Use StackPanel to arrange child objects in a single line that you can align horizontally or vertically.Use StackPanel to arrange child objects in a single line that you can align horizontally or vertically.
24.56.11.Create a StackPanel as content of the Button.
24.56.12.Add a Polyline to the StackPanel
24.56.13.Add an Image to the StackPanel
24.56.14.Add buttons to StackPanel
24.56.15.Nesting StackPanel