0

Why I've got this error by code below on bold lines?

Member IocContainer.ShowWeatherDetailViewModel (and IocContainer.ShowWeatherViewModel) cannot be accessed with an instance reference; qualify it with a type name instead.

error code: CS0176

public class IocContainer 
{
    public static IocContainer Ioc
    {
        get { return App.Current.Resources["ioc"] as IocContainer; }
    }

    // Some other static properties.
    // static constructor
}
IocContainer.Ioc.ShowWeatherDetailViewModel.Item = 
                                    IocContainer.Ioc.ShowWeatherViewModel.SelectedVillage;
Community
  • 1
  • 1
H. Pauwelyn
  • 13,575
  • 26
  • 81
  • 144
  • 3
    Presumably your `ShowWeatherDetailViewModel` property is static as well - so you just need `IocContainer.ShowWeatherDetailViewModel`, or make the property an instance property. – Jon Skeet Dec 25 '15 at 18:50
  • @JonSkeet: yes, but then I don't use the `IocContainer` from the resources in the `App.xaml` file, sir. – H. Pauwelyn Dec 25 '15 at 19:00
  • 1
    If you want to use a particular instance (e.g. the instance in your app.xaml) you should make the method an instance method, not static – Chris Shain Dec 25 '15 at 19:03
  • @ChrisShain: What do you mean, sir? – H. Pauwelyn Dec 25 '15 at 19:05
  • 1
    As Jon mentioned, you probably have the "static" keyword in the definition of the ShowWeatherDetailViewModel member. You should remove it if you want to access the member of a particular instance. – Chris Shain Dec 25 '15 at 19:10
  • 1
    Indeed - we basically can't help you without knowing what you're trying to achieve, with a short but complete example. – Jon Skeet Dec 25 '15 at 19:16

1 Answers1

0

I've found it by made IocContainer.ShowWeatherDetailViewModel and IocContainer.ShowWeatherViewModel an instance property.

Thanks to @JonSkeet and @ChrisShain.

H. Pauwelyn
  • 13,575
  • 26
  • 81
  • 144