WPF:将ScrollBar样式应用于ListBox模板 - 无法将错误对象添加到边框

时间:2009-09-11 19:38:08

标签: wpf listbox styles

我认为这可能是一个简单的问题,但在搜索网络或搜索结果时没有找到任何确定的答案。

我创建了ScrollBar样式(使用标准滚动条模板 - Blend 2)

我不确定如何将此样式“MyScrollStyle”应用于ListBox模板。

我在ListBox模板上看到他们有ScrollViewer - >其中应包含ScrollBar

假设它很简单:

<Setter Property ="Template" value="{Static Resource  MyScrollStyle}"/>

---添加内容---

在模板编辑中经历了很多xaml后,我理解了如何应用样式。我正在尝试将此示例中的滚动视图样式集http://blog.xamltemplates.net/wp-content/uploads/2008/12/scrollviewer.zip添加到我的列表视图模板中,但它会出现以下错误:

System.Windows.Markup.XamlParseException was unhandled
  Message="'ScrollViewer' object cannot be added to 'Border'. Exception has been thrown by the target of an invocation.  Error at object 'System.Windows.Controls.ScrollViewer' in markup file 'MenuModule, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null;component/resources/Resources.xaml' Line 19 Position 26."
  Source="PresentationFramework"
  LineNumber=19
  LinePosition=26
  NameContext="1_T"

感谢任何帮助

谢谢你, 三月

1 个答案:

答案 0 :(得分:0)

您需要修改ListBox.Template,在里面找到ScrollViewer并应用该样式,或禁用ListBox上的滚动并将其放入ScrollViewer中,并附上您的风格。