none
Class/Partial Class Issues RRS feed

  • Question

  • I'm hoping to find an explaination for why something I'm trying to do isn't possible or if it is how to do it. I've tried looking up on the web but trying to word is for an actual search proves very tough.

    I have a treeview. I've created a TreeViewItem called Root and one called Sub. These are currently declared in the windows actual c# class file. I have another class file called NASTT.cs which I have currently as a partial class to this original class. Class Name is MainWindow. I can't reference Root in NASTT I can only reference it from the original file. I also can only create this link of Root being a new treeviewitem from within that original class file. 

    What I'm really hoping is someone can point out is how to make this reference within my other partial class with the same class name: TreeViewItem Root = New TreeViewItem();

    I can fool around and work around this but it's messy from what I'm picturing in my head. 

    Sunday, December 30, 2018 5:50 PM

Answers

  • If it's truly a partial class, then both "files" should be able to access the same fields, even if they are private. But, to be truly a partial class, you've got to have the matching namespaces in both files and matching class names in both files. If they aren't, then that's where your problem lies. Maybe post some of the code?

    ~~Bonnie DeWitt [C# MVP]

    http://geek-goddess-bonnie.blogspot.com

    • Marked as answer by fatalerror0x00 Sunday, December 30, 2018 6:18 PM
    Sunday, December 30, 2018 6:02 PM
    Moderator

All replies

  • If it's truly a partial class, then both "files" should be able to access the same fields, even if they are private. But, to be truly a partial class, you've got to have the matching namespaces in both files and matching class names in both files. If they aren't, then that's where your problem lies. Maybe post some of the code?

    ~~Bonnie DeWitt [C# MVP]

    http://geek-goddess-bonnie.blogspot.com

    • Marked as answer by fatalerror0x00 Sunday, December 30, 2018 6:18 PM
    Sunday, December 30, 2018 6:02 PM
    Moderator
  • You are absolutely correct. The issue was though that I didn't have the using System.Windows.Controls; I was getting the code ready and happened to see a .Controls line and I was like don't tell me that's my problem. 
    Sunday, December 30, 2018 6:17 PM
  • and happened to see a .Controls line and I was like don't tell me that's my problem. 
    Ha ha ha … it's the little things, eh? ;0)  Glad you figured it out, though! =0)

    ~~Bonnie DeWitt [C# MVP]

    http://geek-goddess-bonnie.blogspot.com

    Sunday, December 30, 2018 8:44 PM
    Moderator