none
uwp Listview is not updated RRS feed

  • Question

  • Hi

    It's an uwp blank application  i use a listwiew  to display a list of data

    The list is display but one time ,if i update the list ,changes are not displayed

    Public Class Classdata
        Public Property thename() As String
            Get
                Return name
            End Get
            Set(ByVal value As String)
                value = name
            End Set
        End Property
        Public Property thedate() As String
            Get
                Return hdate
            End Get
            Set(ByVal value As String)
                value = hdate
            End Set
        End Property
        Public Property civildate() As String
            Get
                Return civild
            End Get
            Set(ByVal value As String)
                value = civild
            End Set
        End Property
    
        Public name As String
        Public hdate As String
        Public civild As String
    End Class
    
     The Blank Page item template is documented at https://go.microsoft.com/fwlink/?LinkId=402352&clcid=0x409
    
    Imports System.Text
    ''' <summary>
    ''' An empty page that can be used on its own or navigated to within a Frame.
    ''' </summary>
    Public NotInheritable Class MainPage
        Inherits Page
    #Region "initialize"
      Private list1 As New List(Of Classdata)
      Private Sub initlist()
        Dim data As Classdata
            list1.Clear()
            For iter = 1 To 10
                data = New Classdata
                data.name = "AAAA" & iter.ToString
                data.hdate = Date.Now.ToLongDateString
                data.civild = Date.Today.ToShortDateString
                list1.Add(data)
            Next
        End Sub
        Private Sub showlist()
            Dim myBind As Binding = New Binding()
    
            myBind.Source = list1
            myBind.Mode = BindingMode.OneWay
            Dgvresult.SetBinding(ListView.ItemsSourceProperty, myBind)
        End Sub
    
     Private Sub MainPage_Loading(sender As FrameworkElement, args As Object) Handles Me.Loading
          
         initlist()
         showlist()
        End Sub
    
    Private Sub Buttonthisyear_Click(sender As Object, e As RoutedEventArgs) Handles Buttonthisyear.Click
            list1(1).name = "THENAMECHANGE"
            showlist()
        End Sub
    
    #End Region
    
    
    End Class

    The xaml

    <ListView x:Name="Dgvresult" Width="800" Height="600" ScrollViewer.VerticalScrollBarVisibility="Visible" BorderThickness="3,1,3,3" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="60,20,0,0"> <ListView.ItemTemplate> <DataTemplate> <StackPanel x:Name="stackp" Orientation="Vertical" Width="650" HorizontalAlignment="Left" Margin="69,0,0,0" CornerRadius="6,6,6,6" BorderThickness="2,2,2,2" Height="Auto" > <TextBlock x:Name="namep" Text="{Binding thename}" FontSize="20" FontFamily="Calibri" FontStyle="Normal" FontWeight="Bold" Foreground="DarkSlateBlue" HorizontalAlignment="Left" Margin="492,0,0,0" VerticalAlignment="Center" TextAlignment="Center" HorizontalTextAlignment="Left" Padding="0,0,0,0" TextWrapping="Wrap" /> <TextBlock x:Name="thedate" Text="{Binding thedate}" Margin="270,-26,0,0" FontSize="20" FontStyle="Normal" Foreground="DarkSlateBlue" FontWeight="Bold" FontFamily="Calibri"

    HorizontalAlignment="Left" VerticalAlignment="Center" Padding="0,2,0,0" TextWrapping="Wrap" /> <TextBlock x:Name="civildate" Text="{Binding civildate}" Margin="90,-26,0,0" FontSize="20" FontStyle="Normal" FontWeight="Bold" Foreground="DarkSlateBlue" FontFamily="Calibri" HorizontalAlignment="Left" VerticalAlignment="Center" Padding="0,0,0,0" TextWrapping="Wrap" /> </StackPanel> </DataTemplate> </ListView.ItemTemplate> </ListView>


    When i launch the app  list1 is well displayed but  when i click "buttonthisyear  no change appears

    Thanks



    Wednesday, March 4, 2020 5:14 PM

All replies

  • The key is to setup two-way databinding when working with xaml along with implementing INotifyPropertyChanged interface.


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    Wednesday, March 4, 2020 5:43 PM
  • Hi,

    According to your description, your issue is more related about UWP. And this forum is discussing and asking questions about the vb.net.

    Ask in the following forum.

    https://docs.microsoft.com/answers/index.html

    Thank you for your understanding.

    Thank you for participating in the forum activities.

    Best Regards,

    Julie

    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, March 5, 2020 12:54 AM