Reputation: 242
I have a rather odd question but I somehow hope that it is possible. But after reading a lot I'm rather pessimistic about it.
That's why I'm asking the question here now.
I have some Lists/OberservableCollections that I create by reading from my serial port. Now I have a debug screen in my app where I just display the content of those lists. So far so good. It's working nicely.
Now I have a settings/control page where I want to use the data to produce a control page. For that I need to use the different data streams in recieve and build controls for that.
The streams I get are as following:
I created a quick example on how I want it to look like:
The first stream will be the first column of the view. The second stream is used to decide the minimum and maximum values of the slider or if I even need a slider or something else. Then I have the third stream to set the current values of the sliders/controls. and the last stream is used to add the unit description at the end of the row.
Is it possible to somehow create the controls after I read the streams without creating them in the code behind file? I don't start the reading operations from my view so I can't use the code behind file directly. Maybe I can invoke a function in my code behind file from somewhere else? Or should I implement an event for this? (never done that)
The only option I can think about is to create all the elements in the xaml and control their visibility with bindings but that would be totally unreasonable since I will have around 100 rows of parameters...
I'm really a bit helpless here :/
Best regards, Daniel
Upvotes: 1
Views: 209
Reputation: 242
I actually found an answer already...
While writing the question I remembered that it would be possible to use event handlers. So I looked up how to implement them.
I found an answer really fast but the ObservableCollection fires an avent everytime I add an element to it. I didn't want that since I would have 100 events...
So I found another post here on SO and implemented the extended version of an ObservableCollection.
It can be found here in this post
This extension implements an AddRange
option. It just clears the collection and adds another collection into it. With this the CollectionChanged
event only fires once and I'm happy :D
Upvotes: 1