In c# wpf, I want to make a binding where the textbox changes when an item is added to a listview.

JunYoungLee 161 Reputation points
2022-06-25T07:20:32.207+00:00

I have created a Listview and textbox in C# WPF. This listview has nothing at first, but you can add specific items by pressing a button.
I want to bind the first item name to the textbox when an item is added to the listview. But when I add an item, nothing happens to the textbox. I have attached the code below.

Xaml  
<TextBlock Text="{Binding ElementName=List_EQPID_EI_Rst, Path=Items, Converter={StaticResource ListEI_EQPNameConverter1}, UpdateSourceTrigger=PropertyChanged}" Margin="5 0 0 0"/>      
  
CS, IValueConverter  
public class ListEI_EQPNameConverter1 : IValueConverter  
    {  
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)  
        {  
            var items = value as IList;  
            if (items.Count != 0)  
            {     
                var cast_item = (EQP_Info_EISelect)items[0];  
                return cast_item.strEQPID_EIselect;  
            }  
            else  
            {                  
                return "EQP1";  
            }  
        }  
        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)  
        {  
            throw new NotSupportedException();  
        }  
    }  
Windows Presentation Foundation
Windows Presentation Foundation
A part of the .NET Framework that provides a unified programming model for building line-of-business desktop applications on Windows.
2,626 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
9,918 questions
XAML
XAML
A language based on Extensible Markup Language (XML) that enables developers to specify a hierarchy of objects with a set of properties and logic.
743 questions
0 comments No comments
{count} votes

Accepted answer
  1. Ken Tucker 5,841 Reputation points
    2022-06-25T12:11:48.847+00:00

    In your button command that is adding a new Row to List_EQPID_EI_Rst for the ListView I would raise the PropertChanged event for List_EQPID_EI_Rst after the new item is added so the textbox knows to update.

    0 comments No comments

0 additional answers

Sort by: Most helpful