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,824 questions
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
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();
}
}
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.