Select to view content in your preferred language

How to use an editor in MVVM

859
2
Jump to solution
11-24-2013 06:08 PM
dingkaichen
Deactivated User
Hi,
I am planning to use editor to select elements in the map and do something to the elements. Since I am using MVVM in the project, I was thinking about binding the map object to a map in view model, creating an editor in view model and set the map property as the map in view model. In this way, I can just wire up a button command to a command in view model to use the editor. Unfortunately, when I set the map in view model as the data context of the map in xaml, the map place was blank when program was running. Instead, when I just wire up the map's 'Layers' property to LayerCollection objcet in view model, it works well.
The problem is that when i just binding the 'Layers' property, I can not set the 'map' property of the editor in view model as the map in view, they are not in one place.
I wonder whether there is a way to create an editor in xaml and set its 'map' property as the map in xaml and binding this editor to the editor object in view model.
Look forward to your reply.
0 Kudos
1 Solution

Accepted Solutions
DenisT
by
Deactivated User
I was thinking about binding the map object to a map in view model

Unfortunately, when I set the map in view model as the data context of the map in xaml

There should be only one instance of the Map class.
If you have a Map property in your VM that holds a Map instance, you can write something like that in XAML:
<ContentControl Content="{Binding Map}" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch" />


In this way, I can just wire up a button command to a command in view model to use the editor.

You can use ElementName binding to bind a button to an Editor`s command without a VM.

View solution in original post

0 Kudos
2 Replies
DenisT
by
Deactivated User
I was thinking about binding the map object to a map in view model

Unfortunately, when I set the map in view model as the data context of the map in xaml

There should be only one instance of the Map class.
If you have a Map property in your VM that holds a Map instance, you can write something like that in XAML:
<ContentControl Content="{Binding Map}" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch" />


In this way, I can just wire up a button command to a command in view model to use the editor.

You can use ElementName binding to bind a button to an Editor`s command without a VM.
0 Kudos
dingkaichen
Deactivated User
There should be only one instance of the Map class.
If you have a Map property in your VM that holds a Map instance, you can write something like that in XAML:
<ContentControl Content="{Binding Map}"
HorizontalContentAlignment="Stretch"
VerticalContentAlignment="Stretch" />



You can use ElementName binding to bind a button to an Editor`s command without a VM.


Thank you Denis! You really solved my problem.
0 Kudos