Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>So when you do this:</p> <pre><code>&lt;Window.Resources&gt; &lt;local:SelectWaferButtonViewModel x:Key="SelectWaferButton" /&gt; &lt;/Window.Resources&gt; </code></pre> <p>WPF will create a new instance of the <code>SelectWaferButtonViewModel</code> and add it to it's resources. You then bind to this by setting the <code>DataContext</code> using the <code>StaticResource</code> with the key. </p> <p>However, if you are then creating another <code>SelectWaferButtonViewModel</code> in your code behind and linking up your command to that instance, then it's not the same instance, so changes to the properties of this unbound instance won't effect your UI. There are a couple of ways around it. You can either a) create a single <code>SelectWaferButtonViewModel</code> in the code behind as a property and then bind to that in XAML, or b) Declare your <code>SelectWaferButtonViewModel</code> in XAML as you currently have it and then retrieve that instance in your code behind, like this:</p> <pre><code>SelectWaferButtonViewModel swbvm = (SelectWaferButtonViewModel)this.FindResource("SelectWaferButton"); </code></pre> <p><strong>Edit</strong>: So after seeing your last edit, if you want to go with a) then I would suggest you expose <code>btnSelectWaferViewModel</code> as a property in your <code>WaferTrackerWindowViewModel</code> and then bind to that property with the DataContext of your Window set to the <code>WaferTrackerWindowViewModel</code> instance. So you end up with something like:</p> <pre><code>&lt;DockPanel Name="tvwDockPanel" Width="225" Visibility="{Binding MyButton.IsControlVisible, Converter={StaticResource BoolToVisConverter}}" DockPanel.Dock="Left"&gt; &lt;/DockPanel&gt; </code></pre> <p>and:</p> <pre><code>public class WaferTrackerWindowViewModel :INotifyPropertyChanged { private SelectWaferButtonViewModel btnSelectWaferViewModel; public SelectWaferButtonViewModel MyButton { get { return btnSelectWaferViewModel; } set { btnSelectWaferViewModel = value; OnPropertyChanged("MyButton"); } } //...... </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

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