[英]Custom Control in Scrollviewer
我的問題是如何將自定義控件的ViewModels列表放入Scrollviewer中,該列表由itemtemplate分配。 我讀了一些有關Virtualizingstackpanels和itemcontrol的內容,但是我對此並不了解。
如果有人可以幫助我,那就太好了。
假設您要在滾動查看器中使用同一視圖模型的多個實例,則需要執行以下操作
public class MyViewModel
{
public string SomeProperty {get;set;}
}
在您的視圖中,使用ItemsControl並提供一個DataTemplate並將其綁定到視圖模型列表。
<ScrollViewer VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto">
<ItemsControl ItemsSource="{Binding ListOfViewModels}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<Grid>
<TextBlock Text="{Binding SomeProperty}"/>
</Grid>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</ScrollViewer>
這里的datatemplate是一個帶有文本塊的簡單網格,您也可以在那里使用自己的自定義控件
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.