Merge pull request #238 from MalzSmith/master
Assign ViewModels as DataContext to created Views in MVVM templates
This commit is contained in:
Коммит
66f3823726
|
@ -21,7 +21,9 @@ public class ViewLocator : IDataTemplate
|
|||
|
||||
if (type != null)
|
||||
{
|
||||
return (Control)Activator.CreateInstance(type)!;
|
||||
var control = (Control)Activator.CreateInstance(type)!;
|
||||
control.DataContext = data;
|
||||
return control;
|
||||
}
|
||||
|
||||
return new TextBlock { Text = "Not Found: " + name };
|
||||
|
@ -31,4 +33,4 @@ public class ViewLocator : IDataTemplate
|
|||
{
|
||||
return data is ViewModelBase;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,6 +17,8 @@ type ViewLocator() =
|
|||
if isNull typ then
|
||||
upcast TextBlock(Text = sprintf "Not Found: %s" name)
|
||||
else
|
||||
downcast Activator.CreateInstance(typ)
|
||||
let view = Activator.CreateInstance(typ) :?> Control
|
||||
view.DataContext <- data
|
||||
view
|
||||
|
||||
member this.Match(data) = data :? ViewModelBase
|
||||
|
|
Загрузка…
Ссылка в новой задаче