B
B
bestdk22017-02-06 01:20:45
WPF
bestdk2, 2017-02-06 01:20:45

How to bind View and ViewModel, MVVM Light Toolkit?

Good day.
How to bind a newly created control from View to a collection from ViewModel? Say, as a result of the program execution, a new control is created and it needs to set the content from the ObservableCollection (which is located in the ViewModel). How to organize this connection without violating the MVVM pattern?

Answer the question

In order to leave comments, you need to log in

4 answer(s)
M
Maxim Grekhov, 2017-02-09
@bestdk2

Let's say your View is some UserControl. Then you can do something like
Inside the ViewModel you have a collection of ItemsFromViewModel elements. Then inside your View

...
<ListView ItemsSource="{Binding ItemsFromViewModel}">
...

B
bestdk2, 2017-02-14
@bestdk2

Thank you.

0
0xD34F, 2017-09-13
@un1t

SELECT *
FROM table
WHERE (SELECT array_agg((t->>'category_id')::INT) FROM jsonb_array_elements(data->'items') AS t) && ARRAY[1,3,5]

Or like this:
SELECT *
FROM table
WHERE ARRAY(SELECT t.category_id FROM jsonb_to_recordset(data->'items') AS t(category_id INT)) && ARRAY[1,3,5]

X
x67, 2017-09-13
@x67

SELECT jsv.value#>'{0,name}' as "name" ,jsv.value#>'{0,category_id}' as cat_id
FROM table, jsonb_each(jsonfield) as jsv
WHERE 
whoop_whoop_whoop='abc' 
and jsv.value#>'{0,name}'='B'

the magic extraction happens in the jsonb_each(jsonb field) function the
magic check happens on the jsv object in the WHERE body.
For a complete understanding of how this works, read the postgres manuals. They are well documented!
There you will also find out why the call goes to jsv.value and what will happen if you output jsv.key, as well as which operator is more convenient to use instead of #> in your case

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question