Set padding in silverlight code behind

Xaml:

<UserControl x:Class='TestSilverlightApplication.MainPage'
    xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation' 
    xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'
    xmlns:d='http://schemas.microsoft.com/expression/blend/2008' 
    xmlns:mc='http://schemas.openxmlformats.org/markup-compatibility/2006' 
    mc:Ignorable='d' 
    d:DesignWidth='640' 
    d:DesignHeight='480'>
 
    <Canvas Name="canvas1">
    </Canvas>
</UserControl>

Code behind:

namespace TestSilverlightApplication
{
    public partial class MainPage : UserControl
    {
        Button mybutton = null;
 
        public MainPage()
        {
            InitializeComponent();
        }
 
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            mybutton = new Button { Content = "Hi and Welcome", Width = 150, Height = 25 };
            mybutton.Padding = new Thickness(10, 12, 10, 12); //set the padding using thickness
            Canvas.SetLeft(mybutton, 100);
            Canvas.SetTop(mybutton, 124);
            canvas1.Children.Add(mybutton);
        }
    }
}

Enjoyed this post? Share it!

 

Leave a comment

Your email address will not be published.