无法使用Itemsource

时间:2015-08-22 09:26:46

标签: c# .net wpf xaml listview

我有一个ListView,其中包含dragablz标签插件:

<dragablz:TabablzControl Opacity="0.8" BorderBrush="#FF4C589C"  Margin="10,49,10,10" Background="#FF402D61" TabStripPlacement="Left">

            <dragablz:TabablzControl.InterTabController>
                <dragablz:InterTabController />
            </dragablz:TabablzControl.InterTabController>
            <TabItem Header="Texts">
                <WrapPanel x:Name="textContainer"/>
            </TabItem>
            <TabItem Header="Files">
                <ListView SelectionMode="Extended" x:Name="files" Background="#FF19174B"  AllowDrop="True" ScrollViewer.HorizontalScrollBarVisibility="Disabled" PreviewMouseLeftButtonDown="files_PreviewMouseLeftButtonDown" MouseMove="files_MouseMove">
                    <ListView.DataContext>
                        <local:FileItem/>
                    </ListView.DataContext>

                    <ListView.ItemsPanel>
                        <ItemsPanelTemplate>
                            <WrapPanel/>
                        </ItemsPanelTemplate>
                    </ListView.ItemsPanel>
                    <ListView.ItemTemplate>
                        <DataTemplate>
                            <DockPanel>
                                <local:FileItem/>
                            </DockPanel>
                        </DataTemplate>
                    </ListView.ItemTemplate>
                </ListView>

            </TabItem>
        </dragablz:TabablzControl>

调用者窗口调用包含此InitItems()的窗口的ListView方法,并使用FileItem类型的用户控件填充它:

public int InitItems()
        {
            FileOps.UserDataCollection userData = Utility.userData;
            if (userData != null && userData.userData != null && userData.userData.Count > 0)
            {
                foreach (UserData ud in userData.userData)
                {
                    switch (ud.DataType)
                    {
                        case "file": _FileItems.Add(new FileItem(ud));
                            break;
                        default: break;
                    }
                }
                files.ItemsSource = FileItems;
            }
            return 0;
        }

FileItems_FileItems定义为:

private ObservableCollection<FileItem> _FileItems = new ObservableCollection<FileItem>();
        public ObservableCollection<FileItem> FileItems
        {
            get
            {
                return _FileItems;
            }
        }

使用files.ItemsSource = FileItems;方法中InitItems()行上的断点检查数据时,哪些数据成功获取。

但问题是ListView没有显示用户控件。请告诉我我错过了什么?我只是WPF的初学者。

0 个答案:

没有答案