Note that there are some explanatory texts on larger screens.

plurals
  1. POadding a control to another control in caliburn micro
    text
    copied!<p>I am learning Caliburn Micro and I created a project similar to this tutorial : </p> <p><a href="http://caliburnmicro.codeplex.com/wikipage?title=Basic%20Configuration%2c%20Actions%20and%20Conventions&amp;referringTitle=Documentation" rel="nofollow">http://caliburnmicro.codeplex.com/wikipage?title=Basic%20Configuration%2c%20Actions%20and%20Conventions&amp;referringTitle=Documentation</a> </p> <p>Now I want to create another user control and add it to the above model. so I created a simple user control which is essentially the same as shellViewModel in the tutorial. The view and view model are the same as shellViewModel and ShellView, but with a different name.</p> <p>When I run application, I can see that view is shown on screen, but it is not bind to ViewModel. Should I do any changes to bootstrap so this works? </p> <p>More information: I have created a wpf project similar to tutorial as explained above. It works well.</p> <p>I add a new user control to project and names it NewUCView. So I have the following files in my project:</p> <p>NewUCView.xaml</p> <pre><code>&lt;UserControl x:Class="CaliburnMicroTest.NewUCView" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" mc:Ignorable="d" d:DesignHeight="300" d:DesignWidth="300"&gt; &lt;StackPanel&gt; &lt;TextBox x:Name="Name" /&gt; &lt;Button x:Name="SayHello" Content="Click Me" /&gt; &lt;/StackPanel&gt; &lt;/UserControl&gt; </code></pre> <p>NewUCView.xaml.cs</p> <pre><code>namespace CaliburnMicroTest { /// &lt;summary&gt; /// Interaction logic for NewUC.xaml /// &lt;/summary&gt; public partial class NewUCView : UserControl { public NewUCView() { InitializeComponent(); } } } </code></pre> <p>NewUCViewModel.cs</p> <pre><code>namespace CaliburnMicroTest { using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Windows; using global::Caliburn.Micro; /// &lt;summary&gt; /// TODO: Update summary. /// &lt;/summary&gt; public class NewUCViewModel : PropertyChangedBase { string name; public string Name { get { return name; } set { name = value; NotifyOfPropertyChange(() =&gt; Name); NotifyOfPropertyChange(() =&gt; CanSayHello); } } public bool CanSayHello { get { return !string.IsNullOrWhiteSpace(Name); } } public void SayHello() { MessageBox.Show(string.Format("Hello {0}!", Name)); //Don't do this in real life :) } } } </code></pre> <p>I changed the ShellView as follow and add a reference to NewUCView into it.</p> <pre><code> &lt;StackPanel&gt; &lt;my:NewUCView x:Name="newUC" /&gt; &lt;TextBox x:Name="Name" /&gt; &lt;Button x:Name="SayHello" Content="Click Me" /&gt; &lt;/StackPanel&gt; </code></pre> <p>also changed the ShellViewModel to have a property called newUC which is a NewUCViewModel as follow:</p> <pre><code> private NewUCViewModel newUC=new NewUCViewModel(); public NewUCViewModel NewUC { get { return newUC; } } </code></pre> <p>But when I run this application and press the first click me (which is on user control), it doesn't work. The other button (which is on ShellView) works. </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload