How to Support Listbox Selecteditems Binding with Mvvm in a Navigable Application

How to support ListBox SelectedItems binding with MVVM in a navigable application

Try creating an IsSelected property on each of your data items and binding ListBoxItem.IsSelected to that property

<Style TargetType="{x:Type ListBoxItem}">
<Setter Property="IsSelected" Value="{Binding IsSelected, Mode=TwoWay}" />
</Style>

Bind to SelectedItems from DataGrid or ListBox in MVVM

This will work:

MultiSelectorBehaviours.vb

Imports System.Collections
Imports System.Windows
Imports System.Windows.Controls.Primitives
Imports System.Windows.Controls
Imports System

Public NotInheritable Class MultiSelectorBehaviours
Private Sub New()
End Sub

Public Shared ReadOnly SynchronizedSelectedItems As DependencyProperty = _
DependencyProperty.RegisterAttached("SynchronizedSelectedItems", GetType(IList), GetType(MultiSelectorBehaviours), New PropertyMetadata(Nothing, New PropertyChangedCallback(AddressOf OnSynchronizedSelectedItemsChanged)))

Private Shared ReadOnly SynchronizationManagerProperty As DependencyProperty = DependencyProperty.RegisterAttached("SynchronizationManager", GetType(SynchronizationManager), GetType(MultiSelectorBehaviours), New PropertyMetadata(Nothing))

''' <summary>
''' Gets the synchronized selected items.
''' </summary>
''' <param name="dependencyObject">The dependency object.</param>
''' <returns>The list that is acting as the sync list.</returns>
Public Shared Function GetSynchronizedSelectedItems(ByVal dependencyObject As DependencyObject) As IList
Return DirectCast(dependencyObject.GetValue(SynchronizedSelectedItems), IList)
End Function

''' <summary>
''' Sets the synchronized selected items.
''' </summary>
''' <param name="dependencyObject">The dependency object.</param>
''' <param name="value">The value to be set as synchronized items.</param>
Public Shared Sub SetSynchronizedSelectedItems(ByVal dependencyObject As DependencyObject, ByVal value As IList)
dependencyObject.SetValue(SynchronizedSelectedItems, value)
End Sub

Private Shared Function GetSynchronizationManager(ByVal dependencyObject As DependencyObject) As SynchronizationManager
Return DirectCast(dependencyObject.GetValue(SynchronizationManagerProperty), SynchronizationManager)
End Function

Private Shared Sub SetSynchronizationManager(ByVal dependencyObject As DependencyObject, ByVal value As SynchronizationManager)
dependencyObject.SetValue(SynchronizationManagerProperty, value)
End Sub

Private Shared Sub OnSynchronizedSelectedItemsChanged(ByVal dependencyObject As DependencyObject, ByVal e As DependencyPropertyChangedEventArgs)
If e.OldValue IsNot Nothing Then
Dim synchronizer As SynchronizationManager = GetSynchronizationManager(dependencyObject)
synchronizer.StopSynchronizing()

SetSynchronizationManager(dependencyObject, Nothing)
End If

Dim list As IList = TryCast(e.NewValue, IList)
Dim selector As Selector = TryCast(dependencyObject, Selector)

' check that this property is an IList, and that it is being set on a ListBox
If list IsNot Nothing AndAlso selector IsNot Nothing Then
Dim synchronizer As SynchronizationManager = GetSynchronizationManager(dependencyObject)
If synchronizer Is Nothing Then
synchronizer = New SynchronizationManager(selector)
SetSynchronizationManager(dependencyObject, synchronizer)
End If

synchronizer.StartSynchronizingList()
End If
End Sub

''' <summary>
''' A synchronization manager.
''' </summary>
Private Class SynchronizationManager
Private ReadOnly _multiSelector As Selector
Private _synchronizer As TwoListSynchronizer

''' <summary>
''' Initializes a new instance of the <see cref="SynchronizationManager"/> class.
''' </summary>
''' <param name="selector">The selector.</param>
Friend Sub New(ByVal selector As Selector)
_multiSelector = selector
End Sub

''' <summary>
''' Starts synchronizing the list.
''' </summary>
Public Sub StartSynchronizingList()
Dim list As IList = GetSynchronizedSelectedItems(_multiSelector)

If list IsNot Nothing Then
_synchronizer = New TwoListSynchronizer(GetSelectedItemsCollection(_multiSelector), list)
_synchronizer.StartSynchronizing()
End If
End Sub

''' <summary>
''' Stops synchronizing the list.
''' </summary>
Public Sub StopSynchronizing()
_synchronizer.StopSynchronizing()
End Sub

Public Shared Function GetSelectedItemsCollection(ByVal selector As Selector) As IList
If TypeOf selector Is MultiSelector Then
Return TryCast(selector, MultiSelector).SelectedItems
ElseIf TypeOf selector Is ListBox Then
Return TryCast(selector, ListBox).SelectedItems
Else
Throw New InvalidOperationException("Target object has no SelectedItems property to bind.")
End If
End Function

End Class
End Class

IListItemConverter.vb

''' <summary>
''' Converts items in the Master list to Items in the target list, and back again.
''' </summary>
Public Interface IListItemConverter
''' <summary>
''' Converts the specified master list item.
''' </summary>
''' <param name="masterListItem">The master list item.</param>
''' <returns>The result of the conversion.</returns>
Function Convert(ByVal masterListItem As Object) As Object

''' <summary>
''' Converts the specified target list item.
''' </summary>
''' <param name="targetListItem">The target list item.</param>
''' <returns>The result of the conversion.</returns>
Function ConvertBack(ByVal targetListItem As Object) As Object
End Interface

TwoListSynchronizer.vb

Imports System.Collections
Imports System.Collections.Specialized
Imports System.Linq
Imports System.Windows

''' <summary>
''' Keeps two lists synchronized.
''' </summary>
Public Class TwoListSynchronizer
Implements IWeakEventListener

Private Shared ReadOnly DefaultConverter As IListItemConverter = New DoNothingListItemConverter()
Private ReadOnly _masterList As IList
Private ReadOnly _masterTargetConverter As IListItemConverter
Private ReadOnly _targetList As IList

''' <summary>
''' Initializes a new instance of the <see cref="TwoListSynchronizer"/> class.
''' </summary>
''' <param name="masterList">The master list.</param>
''' <param name="targetList">The target list.</param>
''' <param name="masterTargetConverter">The master-target converter.</param>
Public Sub New(ByVal masterList As IList, ByVal targetList As IList, ByVal masterTargetConverter As IListItemConverter)
_masterList = masterList
_targetList = targetList
_masterTargetConverter = masterTargetConverter
End Sub

''' <summary>
''' Initializes a new instance of the <see cref="TwoListSynchronizer"/> class.
''' </summary>
''' <param name="masterList">The master list.</param>
''' <param name="targetList">The target list.</param>
Public Sub New(ByVal masterList As IList, ByVal targetList As IList)
Me.New(masterList, targetList, DefaultConverter)
End Sub

Private Delegate Sub ChangeListAction(ByVal list As IList, ByVal e As NotifyCollectionChangedEventArgs, ByVal converter As Converter(Of Object, Object))

''' <summary>
''' Starts synchronizing the lists.
''' </summary>
Public Sub StartSynchronizing()
ListenForChangeEvents(_masterList)
ListenForChangeEvents(_targetList)

' Update the Target list from the Master list
SetListValuesFromSource(_masterList, _targetList, AddressOf ConvertFromMasterToTarget)

' In some cases the target list might have its own view on which items should included:
' so update the master list from the target list
' (This is the case with a ListBox SelectedItems collection: only items from the ItemsSource can be included in SelectedItems)
If Not TargetAndMasterCollectionsAreEqual() Then
SetListValuesFromSource(_targetList, _masterList, AddressOf ConvertFromTargetToMaster)
End If
End Sub

''' <summary>
''' Stop synchronizing the lists.
''' </summary>
Public Sub StopSynchronizing()
StopListeningForChangeEvents(_masterList)
StopListeningForChangeEvents(_targetList)
End Sub

''' <summary>
''' Receives events from the centralized event manager.
''' </summary>
''' <param name="managerType">The type of the <see cref="T:System.Windows.WeakEventManager"/> calling this method.</param>
''' <param name="sender">Object that originated the event.</param>
''' <param name="e">Event data.</param>
''' <returns>
''' true if the listener handled the event. It is considered an error by the <see cref="T:System.Windows.WeakEventManager"/> handling in WPF to register a listener for an event that the listener does not handle. Regardless, the method should return false if it receives an event that it does not recognize or handle.
''' </returns>
Public Function ReceiveWeakEvent(ByVal managerType As Type, ByVal sender As Object, ByVal e As EventArgs) As Boolean Implements System.Windows.IWeakEventListener.ReceiveWeakEvent
HandleCollectionChanged(TryCast(sender, IList), TryCast(e, NotifyCollectionChangedEventArgs))

Return True
End Function

''' <summary>
''' Listens for change events on a list.
''' </summary>
''' <param name="list">The list to listen to.</param>
Protected Sub ListenForChangeEvents(ByVal list As IList)
If TypeOf list Is INotifyCollectionChanged Then
CollectionChangedEventManager.AddListener(TryCast(list, INotifyCollectionChanged), Me)
End If
End Sub

''' <summary>
''' Stops listening for change events.
''' </summary>
''' <param name="list">The list to stop listening to.</param>
Protected Sub StopListeningForChangeEvents(ByVal list As IList)
If TypeOf list Is INotifyCollectionChanged Then
CollectionChangedEventManager.RemoveListener(TryCast(list, INotifyCollectionChanged), Me)
End If
End Sub

Private Sub AddItems(ByVal list As IList, ByVal e As NotifyCollectionChangedEventArgs, ByVal converter As Converter(Of Object, Object))
Dim itemCount As Integer = e.NewItems.Count

For i As Integer = 0 To itemCount - 1
Dim insertionPoint As Integer = e.NewStartingIndex + i

If insertionPoint > list.Count Then
list.Add(converter(e.NewItems(i)))
Else
list.Insert(insertionPoint, converter(e.NewItems(i)))
End If
Next
End Sub

Private Function ConvertFromMasterToTarget(ByVal masterListItem As Object) As Object
Return If(_masterTargetConverter Is Nothing, masterListItem, _masterTargetConverter.Convert(masterListItem))
End Function

Private Function ConvertFromTargetToMaster(ByVal targetListItem As Object) As Object
Return If(_masterTargetConverter Is Nothing, targetListItem, _masterTargetConverter.ConvertBack(targetListItem))
End Function

Private Sub HandleCollectionChanged(ByVal sender As Object, ByVal e As NotifyCollectionChangedEventArgs)
Dim sourceList As IList = TryCast(sender, IList)

Select Case e.Action
Case NotifyCollectionChangedAction.Add
PerformActionOnAllLists(AddressOf AddItems, sourceList, e)
Exit Select
Case NotifyCollectionChangedAction.Move
PerformActionOnAllLists(AddressOf MoveItems, sourceList, e)
Exit Select
Case NotifyCollectionChangedAction.Remove
PerformActionOnAllLists(AddressOf RemoveItems, sourceList, e)
Exit Select
Case NotifyCollectionChangedAction.Replace
PerformActionOnAllLists(AddressOf ReplaceItems, sourceList, e)
Exit Select
Case NotifyCollectionChangedAction.Reset
UpdateListsFromSource(TryCast(sender, IList))
Exit Select
Case Else
Exit Select
End Select
End Sub

Private Sub MoveItems(ByVal list As IList, ByVal e As NotifyCollectionChangedEventArgs, ByVal converter As Converter(Of Object, Object))
RemoveItems(list, e, converter)
AddItems(list, e, converter)
End Sub

Private Sub PerformActionOnAllLists(ByVal action As ChangeListAction, ByVal sourceList As IList, ByVal collectionChangedArgs As NotifyCollectionChangedEventArgs)
If sourceList Is _masterList Then
PerformActionOnList(_targetList, action, collectionChangedArgs, AddressOf ConvertFromMasterToTarget)
Else
PerformActionOnList(_masterList, action, collectionChangedArgs, AddressOf ConvertFromTargetToMaster)
End If
End Sub

Private Sub PerformActionOnList(ByVal list As IList, ByVal action As ChangeListAction, ByVal collectionChangedArgs As NotifyCollectionChangedEventArgs, ByVal converter As Converter(Of Object, Object))
StopListeningForChangeEvents(list)
action(list, collectionChangedArgs, converter)
ListenForChangeEvents(list)
End Sub

Private Sub RemoveItems(ByVal list As IList, ByVal e As NotifyCollectionChangedEventArgs, ByVal converter As Converter(Of Object, Object))
Dim itemCount As Integer = e.OldItems.Count

' for the number of items being removed, remove the item from the Old Starting Index
' (this will cause following items to be shifted down to fill the hole).
For i As Integer = 0 To itemCount - 1
list.RemoveAt(e.OldStartingIndex)
Next
End Sub

Private Sub ReplaceItems(ByVal list As IList, ByVal e As NotifyCollectionChangedEventArgs, ByVal converter As Converter(Of Object, Object))
RemoveItems(list, e, converter)
AddItems(list, e, converter)
End Sub

Private Sub SetListValuesFromSource(ByVal sourceList As IList, ByVal targetList As IList, ByVal converter As Converter(Of Object, Object))
StopListeningForChangeEvents(targetList)

targetList.Clear()

For Each o As Object In sourceList
targetList.Add(converter(o))
Next

ListenForChangeEvents(targetList)
End Sub

Private Function TargetAndMasterCollectionsAreEqual() As Boolean
Return _masterList.Cast(Of Object)().SequenceEqual(_targetList.Cast(Of Object)().[Select](Function(item) ConvertFromTargetToMaster(item)))
End Function

''' <summary>
''' Makes sure that all synchronized lists have the same values as the source list.
''' </summary>
''' <param name="sourceList">The source list.</param>
Private Sub UpdateListsFromSource(ByVal sourceList As IList)
If sourceList Is _masterList Then
SetListValuesFromSource(_masterList, _targetList, AddressOf ConvertFromMasterToTarget)
Else
SetListValuesFromSource(_targetList, _masterList, AddressOf ConvertFromTargetToMaster)
End If
End Sub

''' <summary>
''' An implementation that does nothing in the conversions.
''' </summary>
Friend Class DoNothingListItemConverter
Implements IListItemConverter

''' <summary>
''' Converts the specified master list item.
''' </summary>
''' <param name="masterListItem">The master list item.</param>
''' <returns>The result of the conversion.</returns>
Public Function Convert(ByVal masterListItem As Object) As Object Implements IListItemConverter.Convert
Return masterListItem
End Function

''' <summary>
''' Converts the specified target list item.
''' </summary>
''' <param name="targetListItem">The target list item.</param>
''' <returns>The result of the conversion.</returns>
Public Function ConvertBack(ByVal targetListItem As Object) As Object Implements IListItemConverter.ConvertBack
Return targetListItem
End Function
End Class

End Class

Then for the XAML:

<DataGrid ..... local:MultiSelectorBehaviours.SynchronizedSelectedItems="{Binding SelectedResults}" />

And finally the VM:

Public ReadOnly Property SelectedResults As ObservableCollection(Of StatisticsResultModel)
Get
Return _objSelectedResults
End Get
End Property

Credit Goes to: http://blog.functionalfun.net/2009/02/how-to-databind-to-selecteditems.html

Synchronizing multi-select ListBox with MVVM

You can create a Behavior that synchronizes ListBox.SelectedItems with a collection in your ViewModel:

public class MultiSelectionBehavior : Behavior<ListBox>
{
protected override void OnAttached()
{
base.OnAttached();
if (SelectedItems != null)
{
AssociatedObject.SelectedItems.Clear();
foreach (var item in SelectedItems)
{
AssociatedObject.SelectedItems.Add(item);
}
}
}

public IList SelectedItems
{
get { return (IList)GetValue(SelectedItemsProperty); }
set { SetValue(SelectedItemsProperty, value); }
}

public static readonly DependencyProperty SelectedItemsProperty =
DependencyProperty.Register("SelectedItems", typeof(IList), typeof(MultiSelectionBehavior), new UIPropertyMetadata(null, SelectedItemsChanged));

private static void SelectedItemsChanged(DependencyObject o, DependencyPropertyChangedEventArgs e)
{
var behavior = o as MultiSelectionBehavior;
if (behavior == null)
return;

var oldValue = e.OldValue as INotifyCollectionChanged;
var newValue = e.NewValue as INotifyCollectionChanged;

if (oldValue != null)
{
oldValue.CollectionChanged -= behavior.SourceCollectionChanged;
behavior.AssociatedObject.SelectionChanged -= behavior.ListBoxSelectionChanged;
}
if (newValue != null)
{
behavior.AssociatedObject.SelectedItems.Clear();
foreach (var item in (IEnumerable)newValue)
{
behavior.AssociatedObject.SelectedItems.Add(item);
}

behavior.AssociatedObject.SelectionChanged += behavior.ListBoxSelectionChanged;
newValue.CollectionChanged += behavior.SourceCollectionChanged;
}
}

private bool _isUpdatingTarget;
private bool _isUpdatingSource;

void SourceCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
{
if (_isUpdatingSource)
return;

try
{
_isUpdatingTarget = true;

if (e.OldItems != null)
{
foreach (var item in e.OldItems)
{
AssociatedObject.SelectedItems.Remove(item);
}
}

if (e.NewItems != null)
{
foreach (var item in e.NewItems)
{
AssociatedObject.SelectedItems.Add(item);
}
}

if (e.Action == NotifyCollectionChangedAction.Reset)
{
AssociatedObject.SelectedItems.Clear();
}
}
finally
{
_isUpdatingTarget = false;
}
}

private void ListBoxSelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (_isUpdatingTarget)
return;

var selectedItems = this.SelectedItems;
if (selectedItems == null)
return;

try
{
_isUpdatingSource = true;

foreach (var item in e.RemovedItems)
{
selectedItems.Remove(item);
}

foreach (var item in e.AddedItems)
{
selectedItems.Add(item);
}
}
finally
{
_isUpdatingSource = false;
}
}

}

This behavior can be used as shown below:

        <ListBox ItemsSource="{Binding Items}"
DisplayMemberPath="Name"
SelectionMode="Extended">
<i:Interaction.Behaviors>
<local:MultiSelectionBehavior SelectedItems="{Binding SelectedItems}" />
</i:Interaction.Behaviors>
</ListBox>

(note that the SelectedItems collection in your ViewModel has to be initialized; the behavior won't set it, it will only change its content)

Getting ListBox multiselect Items with Binding in WPF

You can send the SelectedItems as a command parameter. For example, you can get the listbox's SelectedItems in a button's command like this.

<ListBox x:Name="listbox" ItemsSource="{Binding MyList}" SelectionMode="Multiple"/>
<Button x:Name="btn" Command="{Binding MyCommand}" CommandParameter="{Binding SelectedItems, ElementName=listbox}" Content="Get Selected Items"/>

Multi selection listbox with bindable selected items DP not binding back to source

I cracked this egg.

The most important thing to me was to avoid using behaviors, or code behind, and I believe I have accomplished this (with some likely needed testing but working so far)

public class MultipleSelectionListBox : ListBox
{
internal bool processSelectionChanges = false;

public static readonly DependencyProperty BindableSelectedItemsProperty =
DependencyProperty.Register("BindableSelectedItems",
typeof(object), typeof(MultipleSelectionListBox),
new FrameworkPropertyMetadata(default(ICollection<object>),
FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnBindableSelectedItemsChanged));

public dynamic BindableSelectedItems
{
get => GetValue(BindableSelectedItemsProperty);
set => SetValue(BindableSelectedItemsProperty, value);
}

protected override void OnSelectionChanged(SelectionChangedEventArgs e)
{
base.OnSelectionChanged(e);

if (BindableSelectedItems == null || !this.IsInitialized) return; //Handle pre initilized calls

if (e.AddedItems.Count > 0)
if (!string.IsNullOrWhiteSpace(SelectedValuePath))
{
foreach (var item in e.AddedItems)
if (!BindableSelectedItems.Contains((dynamic)item.GetType().GetProperty(SelectedValuePath).GetValue(item, null)))
BindableSelectedItems.Add((dynamic)item.GetType().GetProperty(SelectedValuePath).GetValue(item, null));
}
else
{
foreach (var item in e.AddedItems)
if (!BindableSelectedItems.Contains((dynamic)item))
BindableSelectedItems.Add((dynamic)item);
}

if (e.RemovedItems.Count > 0)
if (!string.IsNullOrWhiteSpace(SelectedValuePath))
{
foreach (var item in e.RemovedItems)
if (BindableSelectedItems.Contains((dynamic)item.GetType().GetProperty(SelectedValuePath).GetValue(item, null)))
BindableSelectedItems.Remove((dynamic)item.GetType().GetProperty(SelectedValuePath).GetValue(item, null));
}
else
{
foreach (var item in e.RemovedItems)
if (BindableSelectedItems.Contains((dynamic)item))
BindableSelectedItems.Remove((dynamic)item);
}
}

private static void OnBindableSelectedItemsChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
if (d is MultipleSelectionListBox listBox)
{
List<dynamic> newSelection = new List<dynamic>();
if (!string.IsNullOrWhiteSpace(listBox.SelectedValuePath))
foreach (var item in listBox.BindableSelectedItems)
{
foreach (var lbItem in listBox.Items)
{
var lbItemValue = lbItem.GetType().GetProperty(listBox.SelectedValuePath).GetValue(lbItem, null);
if ((dynamic)lbItemValue == (dynamic)item)
newSelection.Add(lbItem);
}
}
else
newSelection = listBox.BindableSelectedItems as List<dynamic>;

listBox.SetSelectedItems(newSelection);
}
}
}

I was originally swapping the property value that held the selecteditems and this is what was breaking my higher level bindings, but this control modifies the collection directly keeping all references intact. I have not fully tested two way binding yet, but it loads the correct values on initial load and raises all the proper collection changed events when edited in the listbox.

How do I select a new ListBoxItem in C# WPF after I just inserted it automatically

Here is a post that helps answer this question.
But basically:

Create an IsSelected property on your MemoryItem class and bind ListBoxItem.IsSelected to that property.

<ListBox.ItemContainerStyle>
<Style TargetType="{x:Type ListBoxItem}">
<Setter Property="IsSelected" Value="{Binding IsSelected, Mode=TwoWay}" />
</Style>
</ListBox.ItemContainerStyle>

When you want your new item selected, just set IsSelected to true.

IsSelected = true;

And shazam! It should work.

Here is code copied from another answer that may give you more information.

<ListBox ItemsSource="{Binding Items, Source={StaticResource ViewModel}}"
SelectionMode="Extended">
<ListBox.ItemContainerStyle>
<Style TargetType="ListBoxItem">
<Setter Property="IsSelected" Value="{Binding IsItemSelected}"/>
</Style>
</ListBox.ItemContainerStyle>
<ListBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding ItemText}"/>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>

Forgive me for leaving that example exactly as I found it.

ListBox Selected Items in WPF using MVVM

Use Following Code:

XAML:

<Window x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:WpfApplication1"
Title="MainWindow" Height="350" Width="525">
<Grid>
<ListBox ItemsSource="{Binding Months}">
<ListBox.ItemTemplate>
<DataTemplate>
<CheckBox IsChecked="{Binding IsSelected,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" Content="{Binding MonthName}" />
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</Grid>
</Window>

Code:

using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using System.Linq.Expressions;
using System.Printing;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace WpfApplication1
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
this.DataContext = new MainViewModel();
}
}

public class MainViewModel : BaseViewModel
{
public ObservableCollection<MonthViewModel> Months { get; set; }

public MainViewModel()
{
this.Months = new ObservableCollection<MonthViewModel>();

this.Months.Add(new MonthViewModel() { MonthName = "Ocak", MonthNumber = 1 });
this.Months.Add(new MonthViewModel() { MonthName = "Şubat", MonthNumber = 2 });
this.Months.Add(new MonthViewModel() { MonthName = "Mart", MonthNumber = 3 });
this.Months.Add(new MonthViewModel() { MonthName = "Nisan", MonthNumber = 4 });
this.Months.Add(new MonthViewModel() { MonthName = "Mayıs", MonthNumber = 5 });
this.Months.Add(new MonthViewModel() { MonthName = "Haziran", MonthNumber = 6 });
this.Months.Add(new MonthViewModel() { MonthName = "Temmuz", MonthNumber = 7 });
this.Months.Add(new MonthViewModel() { MonthName = "Ağustos", MonthNumber = 8 });


Related Topics



Leave a reply



Submit