开发者

C# which context is bind to a form while a form is loading?

I'd like to know more about the lifecycle of winforms. I know that t开发者_StackOverflow社区he BindingContextChanged event sets the Visible property of the form to true. But I was wondering, which context is bind to the form? What triggers the BindingContextChanged so the forms property Visible is set to true?


I wasn't aware of a tight correlation between BindingContext and Visible, but generally each form simply gets a new BindingContext. If you need to do something funky with separate binding-contexts between different controls, then you have that option by assigning your own BindingContext to some controls.

Looking in reflector, it looks like the BindingContext is set for the first time diring the get in ContainerControl - in fact, that is the only place in the BCL where it appears to be newed:

public override BindingContext get_BindingContext()
{
    BindingContext bindingContext = base.BindingContext;
    if (bindingContext == null)
    {
        bindingContext = new BindingContext();
        this.BindingContext = bindingContext;
    }
    return bindingContext;
}

i.e. it is lazily instantiated when a BindingContext is first needed, and assigning to this.BindingContext causes the event (etc) to be invoked.

Not sure why you think this ties into Visible - care to explain?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜