Setting WindowStartupLocation from ResourceDictionary throws XamlParseException

前端 未结 2 1270
误落风尘
误落风尘 2020-12-20 15:47

When I attempt to set the WindowStartupLocation property through a Setter within a ResourceDictionary, I get a XamlParseExceptio

2条回答
  •  星月不相逢
    2020-12-20 16:22

    The problem is that WindowStartupLocation is not a DependencyProperty so you can't set it in the style setter. Looking in ILSpy the Setter calls

    CheckValidProperty(DependencyProperty property)
    

    and throws a NullArgumentException.

    As WindowStartupLocation is just a CLR property, it can't be set in this way.

    Edit: To respond to the comment. You can still use a ResourceDictionary:

    
        
            
            CenterOwner
        
    
    
    
    

提交回复
热议问题