简体   繁体   English

如何使用不断变化的数据更新 Observable Collection

[英]How to update an Observable Collection with constantly changing data

I am writing some code in C# where an Observable Collection should take the values of characters in a character array and display the absence or presence of a wafer depending on the value after initialization which takes about 30 seconds to complete.我正在 C# 中编写一些代码,其中 Observable Collection 应该采用字符数组中的字符值,并根据初始化后的值显示晶圆的存在或不存在,这大约需要 30 秒才能完成。 However, the models are just displaying blanks without the data involved.但是,模型只是显示空白,没有涉及数据。 I have tried making the array public using {get;我尝试使用 {get; 公开数组set;} as well as introducing a time delay for the initialization but it still displays the blanks. set;} 以及为初始化引入时间延迟但它仍然显示空白。 I would like to ask how to get the Observable Collections to constantly update the Model rather than just being static. I tried changing the UpdateSourceTrigger in the XAML file but there is no change as well.我想问一下如何让 Observable Collections 不断更新 Model 而不仅仅是 static。我尝试更改 XAML 文件中的 UpdateSourceTrigger,但也没有任何变化。 I would be grateful if I could get any pointers to show me in the right direction.如果我能得到任何指示向我展示正确的方向,我将不胜感激。

 public class LPMModel : NotifyPropertyChanged
{
    #region Fields

    private static int nextIndex, nextIndexL = 0;
    private int index;
    private int indexL;
    private bool status;
    private bool enable;
    public char[] WafPreSta;
    public char[] wmapLPM1 { get; set; }
    private readonly ObservableCollection<WaferModel> sloatWaferCollection;

    #endregion Fields

    

  
    public int Index { get => indexL; set => indexL = value; }

    public bool Status { get => status; set => status = value; }

    public bool Enable { get => enable; set => enable = value; }

    
    public ObservableCollection<WaferModel> SlotWaferCollection => sloatWaferCollection;

  

    
    public override string ToString()
    {
        return string.Format("LPM #{0}", Index);
    }

    
    public LPMModel()
    {
        Thread.Sleep(30000);
        indexL = ++nextIndexL;
        index = nextIndex++;
        sloatWaferCollection = new ObservableCollection<WaferModel>();
        while (wmapLPM1 != null)
        {
            for (int i = 25; i > 0; i--)
            {

                switch (wmapLPM1[i-1])
                {
                    case '1':
                        status = true;
                        break;

                    case '0':
                        status = false;
                        break;

                    default:
                        break;
                }

                //status = true;
                sloatWaferCollection.Add(new WaferModel(status, i, this));
                
            }
        }
        
       
    }
}

} }

a quick look at your code, I can't see where you are filling wmapLPM1;快速查看您的代码,我看不到您在哪里填写 wmapLPM1; give more details about your code then hopefully someone can help you properly提供有关您的代码的更多详细信息,然后希望有人可以正确地帮助您

       public class WaferModel 
{

    public int Index { get; set; } public bool Status { get; set; } public bool Enable { get; set; }
}
public class LPMModel : INotifyPropertyChanged
{
    #region Fields

    private static int nextIndex, nextIndexL = 0;
    private int index;
    private int indexL;
    private bool status;
    private bool enable;
    public char[] WafPreSta;
    public char[] wmapLPM1 { get; set; }
    private readonly ObservableCollection<WaferModel> sloatWaferCollection;

    public event PropertyChangedEventHandler PropertyChanged;

    #endregion Fields




    public int Index { get => indexL; set => indexL = value; }

    public bool Status { get => status; set => status = value; }

    public bool Enable { get => enable; set => enable = value; }


    //public ObservableCollection<WaferModel> SlotWaferCollection = new();




    public override string ToString()
    {
        return string.Format("LPM #{0}", Index);
    }


    public LPMModel()
    {
        sloatWaferCollection = new ObservableCollection<WaferModel>();
    }
    public void runLPML()
    {
        Thread.Sleep(30);
        indexL = ++nextIndexL;
        index = nextIndex++;
        int count = 25;
        WaferModel wafer = new();
        while (wmapLPM1 != null)
        {
            for (int i = count; i > 0; i--)
            {

                switch (wmapLPM1[i - 1])
                {
                    case '1':
                        status = true;
                        break;

                    case '0':
                        status = false;
                        break;

                    default:
                        break;
                }

                //status = true;
                wafer.Status = status;
                wafer.Index = i;
                wafer.Enable = true;//false?
                sloatWaferCollection.Add(wafer);
                count -= 1;
                Console.WriteLine(sloatWaferCollection);

            }
        }
    }
}

Here's the code to load wmapLPM1.这是加载 wmapLPM1 的代码。 I tried editing it in markdown format, but I'm not sure about how it may appear in the comments.我尝试以 markdown 格式对其进行编辑,但我不确定它会如何出现在评论中。

void CommMap1_DataReceived(object sender, SerialDataReceivedEventArgs e)  
{  
   byte[] buff = new byte[9600];
   commMap1.Read(buff, 0, 9600);
   string response = System.Text.Encoding.ASCII.GetString(buff, 0, 9600);
   int map1start = response.IndexOf("/");
   string mapLPM1 = response.Substring(map1start + 1, 25);
   wmapLPM1 = mapLPM1.ToCharArray();
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM