Note that there are some explanatory texts on larger screens.

plurals
  1. POWPF, MVVM datagrid row binding
    text
    copied!<p>I am wandering if anyone could help me work out the binding issues I am having?</p> <p>Snippets of Code:</p> <pre><code>&lt;DataGrid AutoGenerateColumns="False" Grid.Column="1" Grid.Row="1" SelectionMode="Single" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" ItemsSource="{Binding PersonList}" CanUserSortColumns="True" SelectedItem="{Binding Path=SelectedPerson}" &gt; &lt;DataGrid.Columns&gt; &lt;DataGridTextColumn Header="FirstName" Width="100" Binding="{Binding FirstName}" /&gt; &lt;DataGridTextColumn Header="LastName" Width="100" Binding="{Binding LastName}" /&gt; &lt;DataGridTemplateColumn Width="140" Header="Operator"&gt; &lt;DataGridTemplateColumn.CellTemplate&gt; &lt;DataTemplate&gt; &lt;ComboBox ItemsSource="{Binding Path=OperatorList}" DisplayMemberPath="FullName" SelectedValue="{Binding Path=SelectedOperator}" /&gt; &lt;/DataTemplate&gt; &lt;/DataGridTemplateColumn.CellTemplate&gt; &lt;/DataGridTemplateColumn&gt; ... &lt;/DataGrid&gt; </code></pre> <p>Above is a snippet of code from the view:</p> <p>Each person in the list is its own viewmodel that has the code snippet below:</p> <pre><code>CollectionView _operatorList; public CollectionView DebtorAgentList { get { return _operatorList; } } Model.Operator _selectedOperator; public Model.Operator SelectedOperator {...} </code></pre> <p>Now the problem I am having is that the SelectedValue binding isn't working and I can't work out why? But what makes it tricky or different (maybe) is that every row in the data grid has its own viewmodel , so in otherwords a datagrid of viewmodels. So what is happening is that FirstName and LastName and Combobox are all filled correctly but I can't seem to get the SelectedValue to bind? P.S. It isnt because of some spell mistake, if there are spelling mistakes is because i renamed methods when I wrote the question etc.</p> <p>Further Details:</p> <p>The above Datagrid is part of a view that has its own viewmodel, this view model fills the datagrid above with a list of people, each person is a viewmodel in essence( well it isn't really a viewmodel but then again its more of a viewmodel than a plane model). It works the way I need it to until I try to bind the SelectedView attribute?</p> <p>Could someone please tell me why that binding might not working?</p> <p>Thanks In advance :D</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