A day with .Net

My day to day experince in .net

Archive for the ‘WPF’ Category

Applying a uniform style to all child elements in a Grid – WPF Tips

Posted by vivekcek on March 25, 2013

So you have Grid with some TextBlock, TextBox and Button controls.How can we apply a Margin to all such controls coming inside Grid.

The solution is Given below


        <Style  x:Key="Margin">
            <Setter Property="Control.Margin" Value="5"></Setter>
        <Style TargetType="Grid" x:Key="GridStyle">
                <Style TargetType="TextBlock" BasedOn="{StaticResource Margin}"></Style>
                <Style TargetType="Button" BasedOn="{StaticResource Margin}"></Style>
                <Style TargetType="TextBox" BasedOn="{StaticResource Margin}"></Style>

<Grid Background="Beige" Style="{StaticResource GridStyle}" x:Name="grdProduct">



Posted in WPF | 1 Comment »