DynamicResource color doesn't work for BorderBrush on a Border - Bug?

前端 未结 5 2035
傲寒
傲寒 2020-12-30 09:42

Visual Studio 2010 | .NET/WPF 4.0

I think this might be a WPF bug, but I can\'t seem to find a bug report about it. To cover the possibility that I\'m just missing s

5条回答
  •  攒了一身酷
    2020-12-30 10:36

    Apparently, the answer to your question is no, this behaviour is not a bug.

    This issue was posted on the Microsoft Connect site by a user and the following reply was given:

    DynamicResources are "looked up" at runtime rather than compile time. The "Dynamic" refers not to "can be dynamically updated at any time" but "we'll look it up later, when it's actually needed."

    If you want to change the border brush at runtime, you'll need to apply a Name="" attribute to the Border in order to touch it from the codebehind, or you can use a Binding to set the value of the brush to a DependencyProperty (if you're using the MVVM pattern or something similar). Change the property and the border brush gets updated by the binding system.

    BTW, this would have been a good question over at StackOverflow--"Why isn't my DynamicResource being updated?"

    Personally, I like the last line best. Microsoft at its most useful! The page can be found here.

提交回复
热议问题