Note that there are some explanatory texts on larger screens.

plurals
  1. POBinding between Usercontrol with listbox and parent control (MVVM)
    primarykey
    data
    text
    <p>I have a UserControl which contains a listbox and few buttons.</p> <pre><code>&lt;UserControl x:Class="ItemControls.ListBoxControl" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"&gt; &lt;Grid&gt; &lt;ListBox:ExtendedListBox SelectionMode="Single" ItemsSource="{Binding LBItems}" Height="184"&gt; &lt;ListBox.ItemTemplate&gt; &lt;DataTemplate&gt; &lt;CheckBox Content="{Binding}"/&gt; &lt;/DataTemplate&gt; &lt;/ListBox.ItemTemplate&gt; &lt;/ListBox&gt; &lt;Button Command="RemoveCommand"/&gt; &lt;/Grid&gt; &lt;/UserControl&gt; </code></pre> <p>And the code behind:</p> <pre><code>public static readonly DependencyProperty RemoveCommandProperty = DependencyProperty.Register("RemoveCommand", typeof(ICommand), typeof(ListBoxControl), null); public ICommand RemoveCommand { get { return (ICommand)GetValue(RemoveCommandProperty); } set { SetValue(RemoveCommandProperty, value); } } public static readonly DependencyProperty LBItemsProperty = DependencyProperty.Register("LBItems", typeof(IEnumerable), typeof(ListBoxControl), null); public IEnumerable LBItems { get { return (IEnumerable)GetValue(LBItemsProperty); } set { SetValue(LBItemsProperty, value); } } </code></pre> <p>I'm using this control in the view like this:</p> <pre><code>&lt;ItemControls:ListBoxControl Height="240" Width="350" LBItems="{Binding Items, Converter={StaticResource ItemsConverter}, Mode=TwoWay}" RemoveCommand="{Binding RemoveCommand}"/&gt; </code></pre> <p>The command works fine, though the listbox binding doesn't. My question is - WHY?</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.
    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