Click here to Skip to main content
15,881,709 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi everybody

How can set Margin property to a number, for example 10 with global Style to controls has created in window under xaml code?

I tried this, but get error...
HTML
<Window.Resources>
    <Style TargetType="UIElement.Control">
        <Setter Property="Margin" Value="10"/>
    </Style>
</Window.Resources>


Are there solution?

Thanks in advanced:)
Posted
Comments
Sandeep Mewara 20-Jul-12 15:58pm    
What error?
hzawary 20-Jul-12 16:04pm    
"Type 'UIElement.Control' was not found."

And when trying only 'UIElement' instead it
"Property 'Margin' was not found in type 'UIElement'."

1 solution

Try this:

<Style TargetType="Control">
	<Setter Property="Margin">
	    Value="10" />
	</Setter>
</Style>

or this:
<Style TargetType="{x:Type Control}">
	<Setter Property="Margin">
		Value="10" />
	</Setter>
</style>


The problem is that Control is not under UIElement. UIElement is another class and does not contain a Margin property.
 
Share this answer
 
v2
Comments
hzawary 20-Jul-12 16:37pm    
I tested your code but dont appear result on the window controls!
Clifford Nelson 20-Jul-12 18:04pm    
That is probably because you have to be specific. In other words, you need to set margin on particular controls (ie TextBox, TextBlock, etc). I have never seen anybody attmept to set properties for Control, or any of the other elements that are not concrete.
hzawary 21-Jul-12 8:01am    
Ok, allright! In fact, I have some 'Button', 'TextBlock' and 'TextBox' on the my window and I want set 'Margin' property (because margin and etc is common property between them) to controls on window in XAML code like to this code:
Foreach(controls item in this.content.controls)
{
item.margin = 10;
}

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900