Click here to Skip to main content
15,881,826 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
hello!
i decided to listen to sergey advice and convert my project from winform application to wpf. now i'm having trouble trying to handle the style for my controls. the problem goes like this:
i have 2 datagrid in my window. one for income sources (green) and one for outcome sources (red color). the project is in the finance field. aniway, i manage to connect the style of the grid to the datagrid. now, i need to have 2 styles, one for each datagrid (because i need the income grid will change the color to green while hover and the outcome grid to red and so for other events).
i need to know, in a situation when i have 2 style called "DgOutcomeStyle" and "DgIncomeStyle", how to make a style goes specific to only one datagrid because right now the style is effect every datagris i create.
hope i'v been clear enough.
thanks,
oron.
<datagrid x:name="DgIncome" xmlns:x="#unknown">
Style="{x:Null}"
HorizontalAlignment="Left"
VerticalAlignment="Top"
Height="669" Width="150"
removed="{x:Null}"
BorderThickness="0"
HeadersVisibility="None" Margin="400,10,0,0" BorderBrush="{x:Null}" Grid.Column="4" GridLinesVisibility="None" FontWeight="SemiBold" FontSize="18"
>

<datagrid x:name="DgOutcome" xmlns:x="#unknown">
HorizontalAlignment="Left"
VerticalAlignment="Top"
Height="669" Width="150"
removed="{x:Null}"
BorderThickness="0"
HeadersVisibility="None" BorderBrush="{x:Null}" Margin="10,10,0,0" GridLinesVisibility="None" FontWeight="SemiBold" FontSize="18"
>
Posted
Updated 19-Mar-15 9:15am
v2
Comments
Sergey Alexandrovich Kryukov 19-Mar-15 22:47pm    
No, the style does not affect every data grid. I'm just curious how did you manage to make all grids to be affected by one style.
—SA

1 solution

UI elements can reference style in XAML using the Style attribute, which value can use StaticResource. This is the way to reference the style defined separately and have different styles for the same type of UI element.

Please start here: https://msdn.microsoft.com/en-us/library/ms745683%28v=vs.110%29.aspx[^].

This CodeProject manual can also be useful: A Guided Tour of WPF – Part 5 (Styles)[^].
First of all, pay attention for the section "With Styles" in the article referenced above. Are you getting the idea?

—SA
 
Share this answer
 
v3

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