.net 为什么WPF控制不同的滚动条样式?
我在WPF TreeView控件旁边有一个WPF WebBrowser控件。两者都具有具有默认特性的默认样式。我没有改变任何东西,除了把它们放在我的WPF窗口。如果查看下面的屏幕截图,可以看到这两个控件有两个不同的滚动条。我不知道为什么会这样 有没有办法使一个控件的滚动条与另一个控件的滚动条相似,或者将它们都默认为windows样式 谢谢.net 为什么WPF控制不同的滚动条样式?,.net,c#-4.0,wpf-controls,styles,scrollbar,.net,C# 4.0,Wpf Controls,Styles,Scrollbar,我在WPF TreeView控件旁边有一个WPF WebBrowser控件。两者都具有具有默认特性的默认样式。我没有改变任何东西,除了把它们放在我的WPF窗口。如果查看下面的屏幕截图,可以看到这两个控件有两个不同的滚动条。我不知道为什么会这样 有没有办法使一个控件的滚动条与另一个控件的滚动条相似,或者将它们都默认为windows样式 谢谢 应用程序资源中似乎有一个自定义主题。WebBrowser没有使用主题中的样式,因为它不是WPF控件,只是Win32控件的包装。因此,您不能使WebBrowse
应用程序资源中似乎有一个自定义主题。
WebBrowser
没有使用主题中的样式,因为它不是WPF控件,只是Win32控件的包装。因此,您不能使WebBrowser滚动条看起来像左侧的滚动条。如果您想摆脱自定义样式,应该将其从资源中删除。WebBrowser
只是本地组件的包装,在WPF中很难处理。在我的项目中,我经历了很多痛苦
因此,从CodePlex尝试是个好主意。它要灵活得多 要回答您的评论:
有没有办法将该主题保留在我的资源中(我的ribbon控件使用它),然后从树视图控件中删除滚动条主题兰丁·马滕斯6月23日19时49分 对 选择1 可以替代控件的默认样式,如下所示:
<Style TargetType="{x:Type TreeView}">
...
</Style>
...
这将更改每个TreeView控件的样式(假设样式是在App.xaml字典中定义的)。如果只希望替代少数控件的样式,可以将其命名为:
<Style x:Key="XTreeViewStyle"
TargetType="{x:Type TreeView}">
...
</Style>
...
并为这些控件显式设置样式(
)。或者,可以在特定上下文(例如网格)中创建样式(从而仅影响网格中的那些控件):
我猜覆盖滚动条的样式并不是专门针对TreeView的。。。它可能是针对TreeView继承自的控件。因此,寻找一种默认样式,它以TreeView、ItemsControl、Control、FrameworkElement或UIElement为目标。找到它后,可以给它命名,也可以将样式移动到更有限的上下文中
例如,您的样式可能设置如下:
<Style TargetType="{x:Type ItemsControl}">
...
</Style>
<Style TargetType="{x:Type Ribbon}">
<Style.Template>
<ControlTemplate>
<ItemsControl>
...
</ItemsControl>
</ControlTemplate>
</Style.Template>
</Style>
<Style TargetType="{x:Type ItemsControl}"
x:Key="XItemsControlStyle">
...
</Style>
<Style TargetType="{x:Type Ribbon}">
<Style.Template>
<ControlTemplate>
<ControlTemplate.Resources>
<Style TargetType="{x:Type ItemsControl}"
BasedOn="{StaticResource XItemsControlStyle}">
...
</Style>
</ControlTemplate.Resources>
<ItemsControl>
...
</ItemsControl>
</ControlTemplate>
</Style.Template>
</Style>
<Style TargetType="{x:Type RibbonItem}">
<Style.Template>
<ControlTemplate>
<ControlTemplate.Resources>
<Style TargetType="{x:Type ItemsControl}"
BasedOn="{StaticResource XItemsControlStyle}">
...
</Style>
</ControlTemplate.Resources>
<ItemsControl>
...
</ItemsControl>
</ControlTemplate>
</Style.Template>
</Style>
...
...
要使ItemsControl样式仅影响功能区,可以将ItemsControl样式移动到功能区的模板中:
<Style TargetType="{x:Type Ribbon}">
<Style.Template>
<ControlTemplate>
<ControlTemplate.Resources>
<Style TargetType="{x:Type ItemsControl}">
...
</Style>
</ControlTemplate.Resources>
<ItemsControl>
...
</ItemsControl>
</ControlTemplate>
</Style.Template>
</Style>
...
...
然而,确切的方法将取决于样式的设置,这可能比我建议的要复杂得多。例如,如果有几个不同的样式都需要使用该ItemsControl样式,则可以使用如下命名和继承:
<Style TargetType="{x:Type ItemsControl}">
...
</Style>
<Style TargetType="{x:Type Ribbon}">
<Style.Template>
<ControlTemplate>
<ItemsControl>
...
</ItemsControl>
</ControlTemplate>
</Style.Template>
</Style>
<Style TargetType="{x:Type ItemsControl}"
x:Key="XItemsControlStyle">
...
</Style>
<Style TargetType="{x:Type Ribbon}">
<Style.Template>
<ControlTemplate>
<ControlTemplate.Resources>
<Style TargetType="{x:Type ItemsControl}"
BasedOn="{StaticResource XItemsControlStyle}">
...
</Style>
</ControlTemplate.Resources>
<ItemsControl>
...
</ItemsControl>
</ControlTemplate>
</Style.Template>
</Style>
<Style TargetType="{x:Type RibbonItem}">
<Style.Template>
<ControlTemplate>
<ControlTemplate.Resources>
<Style TargetType="{x:Type ItemsControl}"
BasedOn="{StaticResource XItemsControlStyle}">
...
</Style>
</ControlTemplate.Resources>
<ItemsControl>
...
</ItemsControl>
</ControlTemplate>
</Style.Template>
</Style>
...
...
...
...
...
选择2
显式设置树视图的样式。这将意味着为TreeView(或者至少是您想要使用的)完成原始样式,给它一个名称,然后在您想要设置样式的TreeView上显式设置。(有关如何操作,请参见选项2)
我相信这些链接将为您提供默认样式: