Defined a list view and one column contains a label and a column like so:

                    <GridViewColumn Header="Document Class" Width="300">
                                <StackPanel Orientation="Horizontal">
                                    <Label Content="{Binding ClassDescription}" HorizontalAlignment="Left" VerticalAlignment="Top" Height="25" Width="100">
                                    <Button x:Name="btnSelectClass" Content="..." HorizontalAlignment="Right" VerticalAlignment="Top" Click="Button_Click"></Button>

Well, partially this is working for me. When the button in that item is clicked, the Button_Click event is fired and I can access the actual row quite easily:
    Private Sub Button_Click(oSender As Object, e As RoutedEventArgs)
        Dim oAttachmentEntry As AttachmentEntry

        oAttachmentEntry = oSender.DataContext

        oAttachmentEntry.ClassDescription = "meh"

    End Sub

What I don't understand is how to get this new "meh" value reflected back on the actual list view that's displayed to the user. After this code is executed the listview still displays the original value.

I reckon I need to somehow invoke "updateSource"? but at this state I'm hopelessly lost. I'm a WPF newbie...


Who is Participating?
WernerVonBraunConnect With a Mentor Author Commented:
Never mind.... I figured it out:

    Private Sub Button_Click(oSender As Object, e As RoutedEventArgs)
        Dim oAttachmentEntry As AttachmentEntry
        Dim oMeh As BindingExpression

        oAttachmentEntry = oSender.DataContext

        oAttachmentEntry.ClassDescription = "meh"

        oMeh = oSender.Parent.Children.item(0).GetBindingExpression(Label.ContentProperty)

    End Sub

Having said that though, I dare say this is a clumsy way of doing it. If anybody can suggest a better and easier way, I'm all ears. If not, I'm accepting this, my own answer soon, but if somewhere out there can tell me how to do this better, ALL THE POINKS ARE BELONG TO YOU.
In general, I'd say that the better method is via the use of the MVVM pattern.
Essentially, the data context of the View (Window) is a View Model class which should implement an OnPropertyChanged() method. That handles the notification of the change to the WPF framework.
I would then use the code-behind button click to assign the ClassDescription Property in the View Model
WernerVonBraunAuthor Commented:
If you could translate that into code that is easy to understand for a total newbie like me, the poinks are yours.
WernerVonBraunAuthor Commented:
ah well
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.