Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6874367
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T04:11:09+00:00 2026-05-27T04:11:09+00:00

I have have a problem with data binding. I have defined a application resource

  • 0

I have have a problem with data binding. I have defined a application resource in XAML like this:

<Application.Resources>
   <local:DataModel x:Key="myDataModel"/>
</Application.Resources>

I bound that model to a list, like this:

<ListView Name="ListBox" 
          ItemsSource="{Binding Source={StaticResource myDataModel}, Path=StatusList}" 
          HorizontalAlignment="Left" 
          HorizontalContentAlignment="Left" 
          VerticalContentAlignment="Top" 
          BorderThickness="0" 
          Background="#000000">
    <ListView.ItemsPanel>
        <ItemsPanelTemplate>
            <StackPanel Orientation="Horizontal"></StackPanel>
        </ItemsPanelTemplate>
    </ListView.ItemsPanel>

    <ListView.ItemTemplate>
        <DataTemplate>
            <Button MinWidth="20" 
                    MinHeight="100" 
                    Background="{Binding Converter={StaticResource StatusConverter}}" 
                    Content="{Binding}" />
        </DataTemplate>
     </ListView.ItemTemplate>
</ListView>

the problem now is that if I change the values of the application resource after binding, the list is not updated. It seems like the binding is done using a copy instead of a reference. The data of the model is updated fine, the PropertyChanged event is raised but the data inside the list never changes.

For your understanding: I have a network client who receives new data every 10 seconds that data needs to be drawn in that list. Right now whenever I receive data, I update the application resource, which as I said should be bound to the list. When I debug the code stopping right in front of the InitializeComponent() method of the XAML file containing the list and wait for a few seconds, I get the latest results of the data transferred, but thats it, it is never updated again.

Can you tell me a better way of defining a globally available instance of my model or a better way of binding it? As you see I need it in more than one part of my program.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T04:11:10+00:00Added an answer on May 27, 2026 at 4:11 am
    public class DataModel
    {
      private IObservableCollection<short> this.statusList;
      public IObservableCollection<short> StatusList
      {
        get {
          return this.statusList;
        }
        set {
          this.statusList = value;
          this.RaisePropertyChanged("StatusList");
        }
      } 
    }
    

    now you can do this one

    this.StatusList = new ObservableCollection<short>();
    

    hope this helps

    EDIT

    Here is an example that I am running without any problems.

    <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">
    
      <Window.Resources>
        <local:DataModel x:Key="myDataModel" />
        <local:StatusConverter x:Key="StatusConverter" />
      </Window.Resources>
    
      <Grid>
    
        <Grid.RowDefinitions>
          <RowDefinition Height="Auto" />
          <RowDefinition />
        </Grid.RowDefinitions>
    
        <Button Grid.Row="0"
                Content="Update"
                Click="Button_Click" />
    
        <ListView Name="ListBox"
                  Grid.Row="1"
                  ItemsSource="{Binding Source={StaticResource myDataModel}, Path=StatusList}"
                  HorizontalAlignment="Left"
                  HorizontalContentAlignment="Left"
                  VerticalContentAlignment="Top"
                  BorderThickness="0"
                  Background="#000000">
          <ListView.ItemsPanel>
            <ItemsPanelTemplate>
              <StackPanel Orientation="Horizontal"></StackPanel>
            </ItemsPanelTemplate>
          </ListView.ItemsPanel>
    
          <ListView.ItemTemplate>
            <DataTemplate>
              <Button MinWidth="20"
                      MinHeight="100"
                      Background="{Binding Converter={StaticResource StatusConverter}}"
                      Content="{Binding}"></Button>
            </DataTemplate>
          </ListView.ItemTemplate>
        </ListView>
    
      </Grid>
    </Window>
    

    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
    {
      /// <summary>
      /// Interaction logic for Window1.xaml
      /// </summary>
      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<short> statusList;
    
        public DataModel() {
          this.StatusList = new ObservableCollection<short>();
    
          this.UpdateStatusList(new[] {(short)1, (short)2, (short)3});
        }
    
        public void UpdateStatusList(IEnumerable<short> itemsToUpdate) {
          foreach (var s in itemsToUpdate) {
            this.StatusList.Add(s);
          }
        }
    
        public ObservableCollection<short> 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;
        }
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a text input area defined like this: <TextBox> <TextBox.Text> <Binding Path=MyProperty> <Binding.ValidationRules>
I have a problem with binding data using BindingSource, typed dataset and DataGridView. My
I have problem with this code: file = tempfile.TemporaryFile(mode='wrb') file.write(base64.b64decode(data)) file.flush() os.fsync(file) # file.seek(0)
I am a learner and i have a problem data binding the dataset. Please
I have a App.xaml template : <Application.Resources> <!-- template for recent history --> <DataTemplate
I'm fairly new to Data binding & XAML, so this probably is fairly simple
I have a problem with data binding my user control into a DGV. When
I have a problem returning data back to the function I want it returned
I have a problem POSTing data via HTTPS in Java. The server response is
I have a problem with data in UITableView. I have UIViewController, that contains UITableView

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.