我是新来的WPF
。我有Listview
,而且我想展示的不仅仅是usercontrol
它。
我使用了项目模板。
像这样的列表视图:
<ListView HorizontalAlignment="Stretch" Margin="0,40,0,0" Name="listView1" VerticalAlignment="Stretch"
ItemTemplate="{StaticResource DriveUserControlDataTemplate}" >
<ListView.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel Width="{Binding (FrameworkElement.ActualWidth), RelativeSource={RelativeSource AncestorType=ScrollContentPresenter}}"
ItemWidth="{Binding (ListView.View).ItemWidth, RelativeSource={RelativeSource AncestorType=ListView}}"
MinWidth="{Binding ItemWidth, RelativeSource={RelativeSource Self}}"
ItemHeight="{Binding (ListView.View).ItemHeight, RelativeSource={RelativeSource AncestorType=ListView}}" />
</ItemsPanelTemplate>
</ListView.ItemsPanel>
</ListView>
<DataTemplate x:Key="DriveUserControlDataTemplate" >
<StackPanel Margin="10">
<c:DriveUserControl Drive="{Binding Name}" EventAdd="DriveUserControlAdd_Click">
</c:DriveUserControl >
</StackPanel>
</DataTemplate>
我想通过这段代码绑定用户控件:
listView1.ItemsSource = DriveInfo.GetDrives()
.Where(item => item.IsReady && item.DriveType == DriveType.Removable)
.ToList();
类DriveInfo
具有名为的属性Name
谁能告诉我为什么它没有绑定?