2009-09-11 39 views
1

我認爲這可能是直接的問題,但在搜索網絡或SO時沒有找到任何確定的答案。WPF:將滾動條樣式應用於列表框模板 - 錯誤對象不能添加到邊界

我創建了一個ScrollBar風格(使用標準滾動詩人模板 - 混合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" 

任何幫助表示讚賞

謝謝 的三月

+0

從模板: \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t TheMar 2009-09-11 19:39:26

+0

如果我錯了,請糾正我的錯誤:我必須爲ScrollViewer編輯模板,並在滾動查看器中使用ScrollBar樣式。我應該將ScrollViewer樣式應用於列表框 – TheMar 2009-09-11 19:50:36

+0

直到現在還沒有運氣 – TheMar 2009-09-12 00:19:41

回答

0

您需要修改ListBox.Template,在裏面找到ScrollViewer並應用樣式,或者在ListBox上停用滾動並將其放入ScrollViewer中。

+0

謝謝Gimlay。如果我把ListBox放在滾動查看器裏面,我將能夠爲LisBoxItems做UI虛擬化 – TheMar 2009-09-12 16:32:20

+0

不,它不會工作。但在大多數情況下,這不是必需的。如果你需要虛擬化編輯ListBox模板。 – gimalay 2009-09-12 21:34:03