I have a simple ListView in my View:
<ListView x:Name="ObjectListView" HorizontalAlignment="Left" Height="105" Margin="253,268,0,0" VerticalAlignment="Top" Width="163" SelectionChanged="ObjectListView_SelectionChanged">
<TextBox Width="100"/>
<Button Width="100" Content="Test"/>
<Label Width="100" Content="Label"/>
</ListView>
In my ViewModel, I have an ObservableCollection, which does a few (to this question irrelevant) things:
public ObservableCollection<Object> ObjectCollection
{
get { return _conversionCollection; }
set
{
if (_conversionCollection != value)
{
_conversionCollection = value;
RaisePropertyChanged("ObjectList");
}
}
}
Ultimatively, those Objects naturally land in the Model(edit: through the help of the RaisePropertyChanged and a few functions), but my problem here is the connection between View and ViewModel.
Currently, I have solved it like this (In the View's code-behind):
public MainWindow()
{
InitializeComponent();
_viewModel = (RibbonViewModel)base.DataContext;
}
private void ObjectListView_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
_viewModel.ObjectCollection.Clear();
foreach(Object item in ObjectListView.SelectedItems)
{
_viewModel.ObjectCollection.Add(item);
}
}
This isn't all too beautiful, so I'd like to do it properly.