Note that there are some explanatory texts on larger screens.

plurals
  1. POTrouble binding SelectedItem in ViewModel - MVVM Light Silverlight 4
    text
    copied!<p>I am using SL4 with MVVM-Light Toolkit. I'm not sure what's going on here. I can't seem to find anything on the web that resolves this issue.. I have a user control that I incorporate into my MainPage.xaml using standard xmlns:local="clr-namespace:WorkOrder.Views" syntax, with a call to local:ListWorkOrdersView further down my page. Using a RelayCommand, I animate in that ListWorkOrdersView window when I click a "List Work Orders" button.</p> <p>I have bound the data on ListWorkOrdersView to an ObservableCollection of test data (for blendibility). What I want to do is bind the SelectedItem of that RadGridView to a property in my ViewModel. If I place a breakpoint on the getter of the SelectedWO property, it fires when I load the control, but the breakpoint is NOT hit if I move it to the setter. Relevant code: </p> <p>ListWorkOrdersView.xaml</p> <pre><code>&lt;UserControl xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation" x:Class="WorkOrder.Views.ListWorkOrdersView" 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" xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity" xmlns:GalaSoft_MvvmLight_Command="clr-namespace:GalaSoft.MvvmLight.Command; assembly=GalaSoft.MvvmLight.Extras.SL4" xmlns:System="clr-namespace:System;assembly=mscorlib" xmlns:ei="http://schemas.microsoft.com/expression/2010/interactions" mc:Ignorable="d" DataContext="{Binding ListWorkOrders, Source={StaticResource Locator}}"&gt; &lt;Grid x:Name="master" DataContext="{Binding ListWorkOrders, Source={StaticResource Locator}}"&gt; &lt;telerik:RadGridView x:Name="gvListWO" IsReadOnly="True" AutoGenerateColumns="False" DataContext="{Binding wo}" SelectedItem="{Binding ElementName=master, Path=DataContext.SelectedWO, Mode=TwoWay}" Grid.ColumnSpan="2" Width="440" Height="330" ItemsSource="{Binding}"&gt; &lt;telerik:RadGridView.Columns&gt; &lt;telerik:GridViewDataColumn DataMemberBinding="{Binding WORK_ORDER_NUMBER}" Header="Work Order Number"/&gt; &lt;telerik:GridViewDataColumn DataMemberBinding="{Binding PROPOSED_BY}" Header="Proposed By"/&gt; &lt;telerik:GridViewDataColumn DataMemberBinding="{Binding DATE_PROPOSED}" Header="Date Proposed"/&gt; &lt;/telerik:RadGridView.Columns&gt; &lt;/telerik:RadGridView&gt; &lt;/Grid&gt; &lt;/UserControl&gt; </code></pre> <p>Relevant ListWorkOrdersViewModel.cs(removed code for databinding the gridview itself)</p> <pre><code>using GalaSoft.MvvmLight; using GalaSoft.MvvmLight.Command; using GalaSoft.MvvmLight.Messaging; using WorkOrder.Model; using System.Collections.ObjectModel; using System.Collections.Generic; using System; namespace WorkOrder.ViewModel { public class ListWorkOrdersViewModel : ViewModelBase { public const string SelectedWOPropertyName = "SelectedWO"; private ObservableCollection&lt;BWorkOrder&gt; _selectedWO; public ObservableCollection&lt;BWorkOrder&gt; SelectedWO { get { return _selectedWO; } set { if (_selectedWO == value) return; _selectedWO = value; RaisePropertyChanged(SelectedWOPropertyName); } } } } </code></pre> <p>Any ideas on why this isn't binding properly? I'm totally at a loss!</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