I have a ResourceDictionary that I have setup to have codebehind.
That codebehind also has a combobox drop down list from my database that I need to initialize. Since this is a "view" level object, I don't want to connect it up to my "model" level objects directly.
So, I need to find a way to get access to this object. The problem is that this "class" is created by the View's call to InitializeComponent()
. So I can't just pass in the stuff I need as params.
I have tried to get the resource and cast it to my "class" but that does not work. (Invalid cast)
ResourceDictionary resource = new ResourceDictionary
{
Source=new Uri("/MyProject;component/MyClass.xaml", UriKind.RelativeOrAbsolute)
};
var myClass = resource as MyClass;
myClass.ListOfItems = listOfItems;
My last resort is to create static methods and pass the references I need that way. But that tightly couples these two classes. So I thought I would see if there is a better way that any one knows...