簡體   English   中英

在WPF中使用模型對象填充表單控件

[英]Populate Form Controls In WPF with Model Object

我想知道我們是否可以輕松地使用通過LINQ填充的對象填充表單控件。 以下是代碼

private void REG_NO_KeyUp(object sender, System.Windows.Input.KeyEventArgs e)
{
    string pattern = "^[A-Z][0-9]*-[0-9]+$";
    regNo = this.REG_NO.Text;

    if (e.Key == System.Windows.Input.Key.Return)
    {
        if (!Regex.Match(regNo, pattern).Success)
        {
            System.Windows.MessageBox.Show("Invalid Card Number");
            this.REG_NO.Background = Brushes.OrangeRed;
            this.REG_NO.Focus();
        }
        else
        {
            this.REG_NO.Background = (Brush)App.Current.FindResource("InputBoxGradient");

            //Fetch Data From Database
            DataAccessLayer DataLayer = new DataAccessLayer();

            if (!DataLayer.FetchRegisteredCard(regNo, ref RegCard))
            {
                System.Windows.MessageBox.Show("No Medical Card Found");
            }
            else
            {
                if (RegCard.STATUS == "VALID")
                {
                }
                else 
                {
                    System.Windows.MessageBox.Show("Card IS Locked Please Contact ADO/Administrator");
                }
            }
        }
    }
}

具有相同屬性名稱和相同屬性的對象

namespace HospitalSystem
{
    using System;
    using System.Collections.Generic;

    public partial class tbl_registration
    {
        public string REG_NO { get; set; }
        public Nullable<System.DateTime> R_DATE { get; set; }
        public string EMP_NO { get; set; }
        public string P_NAME { get; set; }
        public Nullable<System.DateTime> P_DOB { get; set; }
        public string RELATION { get; set; }
        public string BLOOD_GROUP { get; set; }
        public string P_MEDICAL_CAT { get; set; }
        public string MARITAL_STATUS { get; set; }
        public string SEX { get; set; }
        public string STATUS { get; set; }
        public Nullable<System.DateTime> EXP_DATE { get; set; }
        public string PT_NIC { get; set; }
        public string REMARKS { get; set; }
        public Nullable<System.DateTime> STATUS_DATE { get; set; }
        public string EMP_Dept { get; set; }
        public string EMP_Des { get; set; }
        public string EMP_Name { get; set; }
    }
}

其中“ RegCard”是在此行中填充的對象,我想填充表單控件

 if (RegCard.STATUS == "VALID")
 {

 }

請指導我如何做。

您可能正在尋找的是數據綁定,它允許您將對象綁定到表單並將該表單的控件綁定到對象的屬性。 有關文檔和示例,請訪問http://msdn.microsoft.com/zh-cn/library/ms750612%28v=vs.110%29.aspx

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM