diff --git a/templates/csharp/app-mvvm/ViewLocator.cs b/templates/csharp/app-mvvm/ViewLocator.cs index df0cf64..bfad21e 100644 --- a/templates/csharp/app-mvvm/ViewLocator.cs +++ b/templates/csharp/app-mvvm/ViewLocator.cs @@ -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; } -} \ No newline at end of file +} diff --git a/templates/fsharp/app-mvvm/ViewLocator.fs b/templates/fsharp/app-mvvm/ViewLocator.fs index 654cba0..339c850 100644 --- a/templates/fsharp/app-mvvm/ViewLocator.fs +++ b/templates/fsharp/app-mvvm/ViewLocator.fs @@ -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