开发者

MVP - Showing/hiding controls based on business logic

开发者 https://www.devze.com 2023-03-09 18:05 出处:网络
What would be开发者_运维百科 the best way of going about this? I have a method in the presenter that populates various textboxes using a switch statement, but also needs to make sure that only these t

What would be开发者_运维百科 the best way of going about this? I have a method in the presenter that populates various textboxes using a switch statement, but also needs to make sure that only these textboxes are visible, eg.:

switch (operation.CalculationType) {
case CalcType.Type1:
    textbox1.Visible = true
    _view.TextBox1 = "some value";
    break;
case CalcType.Type2:
    textbox1.Visible = true;
    textbox2.Visible = true;
    _view.TextBox1 = "some value";
    _view.TextBox2 = "another value";
    break;

I'm not fond of the idea of exposing a Visible property for each control on the form (theoretically this could lead to exposing all sorts of properties, which just seems wrong to me). Another idea I had was to create a method or event that the presenter calls, telling the form to show/hide the controls, but that kind of means replicating the logic in the presenter.

So what's the "proper" way of doing something this?

Thanks


If the variable _view is not an interface you should make it one, implement it and then add a method or methods that setup which textboxes are visible. This way it is clear in the code what you are trying to do and it not tied to that particular form implementation.

Inteface IFormView
   Sub DisplayType1
   Sub DisplayType2
   ....
End Interface
0

精彩评论

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