How can I change the style -ONCE- for the scrollbars shown by all controls (listbox, treeview, scrollbarviewer, richtextbox, etc...)?
+2
A:
If you will define your Style for a control with no x:Key attribute, it will be applied for all instances of that control.
Try like this:
<Window.Resources>
<Style TargetType="ScrollBar">
<Setter Property="Background" Value="Red"/>
</Style>
</Window.Resources>
<Grid>
<TextBox Margin="24,12,0,0" VerticalScrollBarVisibility="Visible" AcceptsReturn="True" Height="28" VerticalAlignment="Top" HorizontalAlignment="Left" Width="89" />
<ScrollBar Name="scroll" HorizontalAlignment="Right" />
</Grid>
Here you can see that the Style is defined for ScrollBar control and have no x:Key attribute defined so it gets applied to the each ScrollBar instance within Window. Like ScrollBar of TextBox and ScrollBar named scroll also.
Hope this helps!
viky
2009-12-13 08:36:38
A:
Thanks. Finally the problem was solved by setting the style in the Themes/Generic.xaml and (because of custom controls existing in another assembly with they respective resources merged) adding the following to App.xaml...
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Themes/Generic.xaml"/>
<ResourceDictionary Source="MyCtls/MyRes.xaml" />
</ResourceDictionary>
</Application.Resources>
The key point is to merge the Generic.xaml file. Also, if the resource dictionary is in another assembly, it must be referenced as...
<ResourceDictionary Source="pack://application:,,,/OtherAssembly;component/MyCtls/MyRes.xaml"/>
Néstor Sánchez A.
2009-12-13 21:32:49