简体   繁体   English

WPF TabControl ContentTemplate列表

[英]WPF TabControl ContentTemplate List

Inexperienced with WPF, so I need a little help. WPF没有经验,所以我需要一些帮助。 Appreciate the help in advance. 提前感谢帮助。

I have the following class: 我有以下课程:

public class TabDefn
{
    public TabDefn() { }

    public TabDefn(string inFolderName, List<FilesFolder> inFilesFolders)
    {
        folderName = inFolderName;
        FFs = inFilesFolders;
    }

    public string folderName { get; set; }
    public List<FilesFolder> FFs {get; set;}
}

public class FilesFolder
     {
    public FilesFolder() {}

    //public Image image { get; set; }
    public string ffName { get; set; }
    //public Image arrow { get; set; }
}

The TabControl.ItemContent is working fine. TabControl.ItemContent运行正常。 I can't get anything to show up for the TabControl.ContentTemplate . 我无法为TabControl.ContentTemplate展示任何东西。 I've tried many things, but this is where the WPF is right now: 我已经尝试了很多事情,但这就是WPF所处的位置:

<TabControl Grid.Column="1" Grid.Row="1" Visibility="Hidden" Name="Actions">
   <!-- This displays the tab heading perfectly.-->
   <TabControl.ItemTemplate>
      <DataTemplate>
         <TextBlock Text="{Binding folderName}" />
      </DataTemplate>
   </TabControl.ItemTemplate>
   <!-- This is the content of the tab that I can't get anything to show up in.-->
   <TabControl.ContentTemplate>
      <DataTemplate>
         <ListBox ItemsSource="{Binding FF}">
            <ListBox.ItemTemplate>
               <DataTemplate>
                  <StackPanel Orientation="Horizontal">
                     <TextBox Text="{Binding ffName}"  />
                  </StackPanel>
               </DataTemplate>
            </ListBox.ItemTemplate>
         </ListBox>
      </DataTemplate>
   </TabControl.ContentTemplate>
</TabControl>

I don't care if the content changes, so I don't need the INotifyPropertyChanged or ObservableCollection . 我不在乎内容是否更改,因此不需要INotifyPropertyChangedObservableCollection However, if I have to put all that code in, so be it. 但是,如果我必须将所有代码都放入其中,那就这样吧。

You declare FF as field which is invalid binding source. 您将FF声明为无效绑定源的字段。 You need to convert it into property 您需要将其转换为属性

public List<FilesFolders> FF { get; set; }

and initialize it for example in TabDefn constructor. 并在TabDefn构造函数中对其进行初始化。 You can find more as to what is a valid binding source on MSDN 您可以找到有关MSDN上有效绑定源的更多信息

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM