Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <pre><code>public class DataModel { private IObservableCollection&lt;short&gt; this.statusList; public IObservableCollection&lt;short&gt; StatusList { get { return this.statusList; } set { this.statusList = value; this.RaisePropertyChanged("StatusList"); } } } </code></pre> <p>now you can do this one</p> <pre><code>this.StatusList = new ObservableCollection&lt;short&gt;(); </code></pre> <p>hope this helps</p> <p><strong>EDIT</strong></p> <p>Here is an example that I am running without any problems.</p> <pre><code>&lt;Window x:Class="WpfStackOverflowSpielWiese.Window1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="clr-namespace:WpfStackOverflowSpielWiese" Title="Window1" Height="300" Width="300"&gt; &lt;Window.Resources&gt; &lt;local:DataModel x:Key="myDataModel" /&gt; &lt;local:StatusConverter x:Key="StatusConverter" /&gt; &lt;/Window.Resources&gt; &lt;Grid&gt; &lt;Grid.RowDefinitions&gt; &lt;RowDefinition Height="Auto" /&gt; &lt;RowDefinition /&gt; &lt;/Grid.RowDefinitions&gt; &lt;Button Grid.Row="0" Content="Update" Click="Button_Click" /&gt; &lt;ListView Name="ListBox" Grid.Row="1" ItemsSource="{Binding Source={StaticResource myDataModel}, Path=StatusList}" HorizontalAlignment="Left" HorizontalContentAlignment="Left" VerticalContentAlignment="Top" BorderThickness="0" Background="#000000"&gt; &lt;ListView.ItemsPanel&gt; &lt;ItemsPanelTemplate&gt; &lt;StackPanel Orientation="Horizontal"&gt;&lt;/StackPanel&gt; &lt;/ItemsPanelTemplate&gt; &lt;/ListView.ItemsPanel&gt; &lt;ListView.ItemTemplate&gt; &lt;DataTemplate&gt; &lt;Button MinWidth="20" MinHeight="100" Background="{Binding Converter={StaticResource StatusConverter}}" Content="{Binding}"&gt;&lt;/Button&gt; &lt;/DataTemplate&gt; &lt;/ListView.ItemTemplate&gt; &lt;/ListView&gt; &lt;/Grid&gt; &lt;/Window&gt; </code></pre> <p><br/></p> <pre><code>using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.ComponentModel; using System.Globalization; using System.Windows; using System.Windows.Data; using System.Windows.Media; namespace WpfStackOverflowSpielWiese { /// &lt;summary&gt; /// Interaction logic for Window1.xaml /// &lt;/summary&gt; public partial class Window1 : Window { public Window1() { this.InitializeComponent(); } private void Button_Click(object sender, RoutedEventArgs e) { var dataModel = this.TryFindResource("myDataModel") as DataModel; if (dataModel != null) { dataModel.UpdateStatusList(new[] {(short)1, (short)2, (short)3}); } } } public class DataModel : INotifyPropertyChanged { private ObservableCollection&lt;short&gt; statusList; public DataModel() { this.StatusList = new ObservableCollection&lt;short&gt;(); this.UpdateStatusList(new[] {(short)1, (short)2, (short)3}); } public void UpdateStatusList(IEnumerable&lt;short&gt; itemsToUpdate) { foreach (var s in itemsToUpdate) { this.StatusList.Add(s); } } public ObservableCollection&lt;short&gt; StatusList { get { return this.statusList; } set { this.statusList = value; this.RaisePropertyChanged("StatusList"); } } private void RaisePropertyChanged(string propertyName) { var eh = this.PropertyChanged; if (eh != null) { eh(this, new PropertyChangedEventArgs(propertyName)); } } public event PropertyChangedEventHandler PropertyChanged; } public class StatusConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { if (value is short) { switch ((short)value) { case 1: return Brushes.Red; case 2: return Brushes.Orange; case 3: return Brushes.Green; } } return Brushes.White; } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { return DependencyProperty.UnsetValue; } } } </code></pre>
    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.
 

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