2,857 questions
Hi, the binding doesn't work because Tangents is not property. Try following demo:
<Window x:Class="WpfApp1.Window04"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WpfApp04"
mc:Ignorable="d"
Title="Window04" Height="450" Width="800">
<Window.DataContext>
<local:ViewModel/>
</Window.DataContext>
<Grid>
<ListBox ItemsSource="{Binding Tangents}">
<ListBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding StartPoint.Description, UpdateSourceTrigger=PropertyChanged}"/>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</Grid>
</Window>
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Windows;
namespace WpfApp04
{
public class ViewModel
{
public ViewModel()
{
Tangents.Add(new Tangent(new Point2d()));
}
public IList<ITangent> Tangents { get; set; } = new ObservableCollection<ITangent>();
}
public class Tangent : ITangent
{
public Tangent(Point2d pt) => StartPoint = pt;
public IPoint2d StartPoint { get; set; }
}
public interface ITangent
{
IPoint2d StartPoint { get; set; }
}
public class Point2d : IPoint2d
{
public string Description { get; set; } = "new Description";
}
public interface IPoint2d
{
string Description { get; set; }
}
}