Question

Inexperienced with WPF, so I need a little help. 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. I can't get anything to show up for the TabControl.ContentTemplate. I've tried many things, but this is where the WPF is right now:

<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. However, if I have to put all that code in, so be it.

Était-ce utile?

La solution

You declare FF as field which is invalid binding source. You need to convert it into property

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

and initialize it for example in TabDefn constructor. You can find more as to what is a valid binding source on MSDN

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top