开发者

MVVM Class Instantiation and Args

I'm trying to whip my brain into MVVM mode here.

I have a Grid in my view, and various methods for manipulating it and adding shapes to it in my viewmodel. I realize that I should try to avoid that sort of thing in the VM, so I moved those methods into there own class. What I'm trying to figure out is

a) Where should an instance of the new class be created? Currently I've got it in my VM, using IoC.Get()

b) The NewClass needs to get a hold of the Grid in the view, how can I do that? (The only thing I can think of is to have the VM get a reference to its View, and p开发者_StackOverflowass the Grid into the NewClass, but that doesn't seem like the best way to do it)


A) look at using Coroutines if you need to manipulate the grid in a way you're not able to through the viewmodel. A reference to the view gets passed in the ActionExecutionContext.

public interface IResult
{
    void Execute(ActionExecutionContext context);
    event EventHandler<ResultCompletionEventArgs> Completed;
}

public class ActionExecutionContext
{
    public ActionMessage Message;
    public FrameworkElement Source;
    public object EventArgs;
    public object Target;
    public DependencyObject View;
    public MethodInfo Method;
    public Func<bool> CanExecute;
    public object this[string key];
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜