Attached properties should have static getter and setter methods, in your case:
public static string GetMyCustom(DependencyObject obj)
{
return (string)obj.GetValue(MyCustomProperty);
}
public static void SetMyCustom(DependencyObject obj, string value)
{
obj.SetValue(MyCustomProperty, value);
}
Having said that you would still have to have an instance of a DependencyObject
-derived class to set the property on, which System.Windows.Application
is not. In other words, you can't set an attached property on your MyApp object.
Instead of using an attached property, you might just add a plain CLR property to your BaseApp
class:
public class BaseApp : Application
{
public string MyCustom { get; set; }
}
and use it like this:
<local:BaseApp x:Class="MyNamespace.MyApp" ...
MyCustom="Hello">
<Application.Resources>
</Application.Resources>
</local:BaseApp>