Note that there are some explanatory texts on larger screens.

plurals
  1. POWPF DataBinding Issues - Possible Noob Problems
    primarykey
    data
    text
    <p>I am trying to bind a ViewModel property of type Visibility to the visibility property on a Dock Panel:</p> <p><em><strong>Updated ViewModel Code</em></strong>:</p> <pre><code>public class SelectWaferButtonViewModel : INotifyPropertyChanged { private bool isClicked; public SelectWaferButtonViewModel() { isClicked = false; } public bool IsControlVisible { get { return isClicked; } set { isClicked = value; OnPropertyChanged("IsControlVisible"); } } public event PropertyChangedEventHandler PropertyChanged; public void OnButtonClick() { if (isClicked) { IsControlVisible = false; } else { IsControlVisible = true; } } protected virtual void OnPropertyChanged(string property) { if (PropertyChanged != null) { PropertyChanged(this, new PropertyChangedEventArgs(property)); } } } </code></pre> <p><em><strong>and here is my updated XAML code</em></strong>:</p> <pre><code> &lt;DockPanel Name="tvwDockPanel" Width="200" Visibility="{Binding IsControlVisible, FallbackValue=Collapsed, Converter={StaticResource BoolToVisConverter}}" DockPanel.Dock="Left"&gt; &lt;DockPanel DockPanel.Dock="Top" Height="22"&gt; &lt;/DockPanel&gt; </code></pre> <p>and I set the data context in the code behind with this line:</p> <pre><code> tvwDockPanel.DataContext = btnSelectWaferViewModel; </code></pre> <p>where btnSelectWaferViewModel is the ViewModel object for this situation.</p> <p><em><strong>and for fun, here is my code behind</em></strong>:</p> <pre><code>public partial class WaferTrackerWindow : Window { List&lt;ISubscribeEvents&gt; subscriptionList; SelectWaferButtonViewModel btnSelectWaferViewModel; public WaferTrackerWindow() { InitializeComponent(); this.InstantiateObjects(); this.SubscribeEvents(); this.SetDataContexts(); } #region Methods private void SetDataContexts() { tvwDockPanel.DataContext = btnSelectWaferViewModel.IsControlVisible; } private void SubscribeEvents() { foreach (ISubscribeEvents subscriber in subscriptionList) { subscriber.SubscribeEvents(); } } private void InstantiateObjects() { btnSelectWaferViewModel = new SelectWaferButtonViewModel(); subscriptionList = new List&lt;ISubscribeEvents&gt;(); subscriptionList.Add( new Classes.WaferTrackerWindow.SelectWaferButtonView(btnSelectWafer, btnSelectWaferViewModel)); } #endregion } </code></pre> <p>All I want to do click the button btnSelectWafer and have the tvwDockPanel's visibility property to get to set to Visible via binding. Then when you click again on btnSelectWafer, tvwDockPanel's visibility property gets set back to Collapsed again. tvwDockPanel's visibility will only ever be either Collapsed or Visible.</p> <p>Any help would be awesome, I am rather new to this whole data binding concept.</p>
    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.
 

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