当我在运行时生成它时,我将行为(Blend SDK 中的行为)附加到 UIElement。我还有两个按钮来触发Detach()和Attach() - 基本上是启用或禁用该行为。
问题是:在我Detach()行为之后,Attach()未能将行为恢复到依赖对象,然后保持无行为:
// Declare the dependency object and behavior at class scope
MyControl c = new MyControl();
MyBehavior b = new MyBehavior();
// Function that generate UI Controls with behavior attached
b.Attach(c);
// Function that detach behavior from dependency object
b.Detach();
// Function that re-attach behavior to the same object after it has been detached
b.Attach(c); // <-- Do not see the behavior...
为什么行为没有重新附加?是否有解决方案或解决方法来打开或关闭行为?