0

I'm working on a project where an application displays data by pulling it from a file and displaying a new data value every second. (edit: consolidated code at the end).

While displaying changing data in textblocks work fine, what I'm trying to do is not only display it momentarily but have a display where the data keeps adding to a list and displaying and which can also be saved later (i.e I'm trying to use ListView and ObservableCollection). There's a few components that I'm struggling with:

Working with ListView: I initially did this but the "get" keeps returning null.

    public ListView Data2
    {
        get { return Data2_; }
        set
        {
            Data2_= value;
            NotifyPropertyChanged("Data2");
        }
    }

I was able to create a variable with an increasing list but have trouble connecting it to the UI. I'm not getting any values to show up though. Any help to go about this would be appreciated! Sorry I'm just learning application building so this is all new to me.

Edit: what I have now:

DataDisplay.xaml file:

        <ListView x:Name="Data2" Height="100">
            
            <ListView.Resources>
                <Style TargetType="{x:Type ListViewItem}">

                </Style>
            </ListView.Resources>
            
            <ListView.DataContext>
                <local:GetData/>
            </ListView.DataContext>
            
            <ListView.View>
                <GridView>
                    <GridViewColumn Header="Data 2" Width="250" DisplayMemberBinding="{Binding DATA2_}" />

                </GridView>
            </ListView.View>
        </ListView>

DataDisplay.xaml.cs file:

public partial class DataDisplay : Window { private ObservableCollection data_2;

public DataDisplay ()
{
    InitializeComponent();

    data_2 = new ObservableCollection<uint>(); 
}


private async void AddData(object sender, EventArgs e)
{
    cnt++;
            data_2.Add(data2_;);
            Data.data2 = data2_;
}

}

3rd .cs file:

public class GetData: INotifyPropertyChanged
{
    private ObservableCollection<uint>Data2;

    public ObservableCollection<uint> DATA2_
    {
        get { return Data2; }
        set
        {
            Data2 = value;
            NotifyPropertyChanged("DATA2_");
        }
    }
  • May I ask what the specific xaml code and code are, indicating that when the collection of collection objects changes, only ObservableCollection will send a notification to update the UI – Housheng-MSFT May 06 '22 at 07:25
  • @Housheng-MSFT I'm working on existing work so I shared what I added. To note- I see the list accumulating in data_2 but I'm struggling how to "send a notification to update the UI" – user14258115 May 06 '22 at 15:10

0 Answers0