Note that there are some explanatory texts on larger screens.

plurals
  1. POBinding between UserControl and MainWindow issue
    primarykey
    data
    text
    <p>I'm missing something in this binding because it doesn't work. This is for learning purposes, if you see how this can be improved please tell me. But besides that I'm also interested in know why this is not working.</p> <p>In my <code>MainWindow</code> there is a <code>CheckBox</code> with a command bound to it: <code>checkCommand</code>.</p> <p>In <strong>RootViewModel.cs</strong>:</p> <pre><code> public Command checkCommand { get; set; } public RootViewModel() { checkCommand = new Command(mark); } private void mark() { myThingsCollection[0].marked= true; } </code></pre> <p>This command is working properly, and it also changes the state of <code>marked</code> to <code>true</code> (I've tested this with a <code>MessageShowBox</code>).</p> <p>I've previously added the UC to a <code>ObsevableCollection&lt;UC&gt;</code> (<code>myThingsCollection</code>) and bound it to a <code>ItemsControl</code> this way in <strong>MainWindow.cs</strong></p> <pre><code>&lt;ItemsControl ItemsSource="{Binding myThingsCollection}"&gt; &lt;DataTemplate&gt; &lt;!--I've ommited some parts here--!&gt; &lt;local:UC/&gt; &lt;/DataTemplate&gt; &lt;/ItemsControl.ItemTemplate&gt; &lt;/ItemsControl&gt; </code></pre> <p>The UC is displayed correctly.</p> <p><code>marked</code> is a property of the <code>UCViewModel</code>:</p> <pre><code>class UCViewModel { #region Implementation of INotifyPropertyChanged private bool _marked; public bool marked { get { return _marked; } set { _marked= value; OnPropertyChanged("marked"); } } } </code></pre> <p>That <code>UserControl</code> (<code>UC</code>) has a <code>CheckBox</code> that I bind this way:</p> <pre><code> &lt;CheckBox Content="Hello!" IsChecked="{Binding marked}"/&gt; </code></pre> <p>And set the <code>DataContext</code> this way (in the code behind <strong>UC.cs.xaml</strong>)</p> <pre><code> public UC() { UCViewModel context = new UCViewModel(); DataContext = context; InitializeComponent(); } </code></pre> <p>But it doesn't work. I don't know what it's missing. By the way I'm pretty sure that this is not a good approach to this problem, is there an easier way? Thanks</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    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. 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