Using Styles in WPF
-
Wednesday, October 11, 2006 3:22 AM
Hi
I using a Tabcontrol and binding the items dynamically to a List of strings. I have written two different Styles in my Application Resource, Is it possible for me to use the first Style for the first two TabItem in the control and the Second style for the rest of the tabs that are created in the control.
All Replies
-
Wednesday, October 11, 2006 6:15 AMYes, the way to go is to not add a x:Key attribute for the style you want to be on the rest of the items. Add the x:Key attribute to the style that you want to use for the first 2 items. Then you can manually specify the Style name for the first 2 items and not specify the Style at all for the rest. This will achieve the desired effect.
-
Friday, October 13, 2006 3:33 AM
hi
Iam tring to directly bind the "ItemSource" property of the Tabcontrol to a list of String so how to set the style's of the items...... Could you help me out with a code snippet
Regards
Ragu
-
Friday, October 13, 2006 1:33 PMModerator
you can do something like this
tabc.ItemsSource =
new String[] { "qa", "qa1", "qa2", "qa3" };//tabc is the tabcontrol TabItem ti = tabc.ItemContainerGenerator.ContainerFromIndex(0) as TabItem;ti.Style =
this.FindResource("t1") as Style; TabItem ti1 = tabc.ItemContainerGenerator.ContainerFromIndex(1) as TabItem;ti1.Style =
this.FindResource("t2") as Style; -
Friday, October 13, 2006 5:40 PM
TabControl.ItemContainerStyleSelector is designed for such kinda scenario.
Sheva -
Friday, October 13, 2006 5:57 PMModeratorI was trying to avoid writing another class, because it does not depend on any properties
-
Tuesday, October 17, 2006 4:21 AM
Thanks Guys it worked..
Regards
Ragu

