0

I am making a custom user control using the DataGrid format to be used in an HMI application. The only way data can be passed to the user control once it is placed in the HMI application is through the user control's parameters. I have made an example project to illustrate what I will have to do.

I have two items in a list. Each have a field called "TestBool" which needs to populated based on the value of the respective Unit Control parameter (TestBool1 and TestBool2). There is also a text field will say Yes/No or Si/No depending on if the "IsSpanish" parameter is true. When I place this Control in my application, changing the parameter values does not update the control display. Any advice?

Notes: I am not defining a view object (is that called an MVVM model?) because the parameters have to be in the user control class definition to be exposed in the application I am placing it in. Also, the project is a Class Library because I need to build a DLL file.

public partial class UserControl1 : UserControl
{

    private List<User> users = new List<User>()
    {
        new User()
        {
            Id = 1,
            TestBool = true,
            TestString = "YES"
        },
        new User()
        {
            Id = 2,
            TestBool = false,
            TestString = "NO"
        }
    };

    public UserControl1()
    {
        InitializeComponent();

        dgSimple.ItemsSource = users;

    }
    public bool TestBool1
    {
        get { return _testBool1; }
        set
        {
            _testBool1 = value;
            users[0].TestBool = value;
            if ((value == true) & (IsSpanish == false)) { users[0].TestString = "YES"; }
            else if ((value == true) & (IsSpanish == true)) { users[0].TestString = "SI"; }
            else if ((value == false) & (IsSpanish == false)) { users[0].TestString = "NO"; }
            else if ((value == false) & (IsSpanish == true)) { users[0].TestString = "NO"; }
        }
    }

    private bool _testBool1;

    public bool TestBool2
    {
        get { return _testBool2; }
        set
        {
            _testBool2 = value;
            users[1].TestBool = value;
            if ((value == true) & (IsSpanish == false)) { users[1].TestString = "YES"; }
            else if ((value == true) & (IsSpanish == true)) { users[1].TestString = "SI"; }
            else if ((value == false) & (IsSpanish == false)) { users[1].TestString = "NO"; }
            else if ((value == false) & (IsSpanish == true)) { users[1].TestString = "NO"; }
        }
    }

    private bool _testBool2;

    public bool IsSpanish
    {
        get { return _isSpanish; }
        set
        {
            _isSpanish = value;
        }
    }

    private bool _isSpanish;

}

public class User
{
    public int Id { get; set; }

    public bool TestBool { get; set; }

    public String TestString { get; set; }
}

}

0 Answers0