안녕하세요.
WPF가 아직 초보라서… 하루종일 여기에서 살고 있습니다.
항상 감사드립니다.
제가 문의드리고자하는 것은
- Lines라는 PointCollection 프로퍼티를 ItemsSource로 받고 있을때, Item에 해당하는 항목에 Binding 될 때 오류가 나타납니다.(바인딩 에러)
오류는 아래와 같이 나옵니다.(바인딩 에러 항목도 나오고요)
System.Windows.Data Error: 2 : Cannot find governing FrameworkElement or FrameworkContentElement for target element. BindingExpression:(no path); DataItem=null; target element is ‘EllipseGeometry’ (HashCode=14867369); target property is ‘Center’ (type ‘Point’) …이하 중략
LinePointsViewModel.cs
namespace Canvas.Add.Lines.ViewModels
{
public class LinePointsViewModel
:Screen
{
public LinePointsViewModel()
{
_linePoints = new PointCollection();
//_linePoints.Changed += CollectionChanged;
}
private void CollectionChanged(object sender, EventArgs e)
{
//내부적으로 포인트 추가 삭제, 변경이 있을 떄 PropertyChange하는 로직이
//있으면 좋겠는데...
}
private PointCollection _linePoints;
public PointCollection LinePoints
{
get { return _linePoints; }
set
{
_linePoints = value;
NotifyOfPropertyChange(() => LinePoints);
}
}
}
}
LineViewModel.cs
namespace Canvas.Add.Lines.ViewModels
{
public class LineViewModel
:Screen
{
public LineViewModel()
{
//var pClass = IoC.Get<LinePointsViewModel>();
//Lines = new ObservableCollection<LinePointsViewModel>();
Lines = new TrulyObservableCollection<LinePointsViewModel>();
}
private TrulyObservableCollection<LinePointsViewModel> _lines;
public TrulyObservableCollection<LinePointsViewModel> Lines
{
get { return _lines; }
set
{
_lines = value;
NotifyOfPropertyChange(() => Lines);
}
}
}
}
LineView.xaml
<UserControl x:Class="Canvas.Add.Lines.Views.LineView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:Canvas.Add.Lines.Views"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<ItemsControl ItemsSource="{Binding Lines, UpdateSourceTrigger=PropertyChanged}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<Canvas />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<Canvas>
<Polyline Points="{Binding LinePoints, UpdateSourceTrigger=PropertyChanged}"
StrokeThickness="2.0"
Stroke="Black" />
<ItemsControl ItemsSource="{Binding LinePoints, UpdateSourceTrigger=PropertyChanged}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<Canvas />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<Path StrokeThickness="1.0"
Stroke="Black"
Fill="MistyRose">
<Path.Data>
<EllipseGeometry Center="{Binding }"
RadiusX="4"
RadiusY="4" />
</Path.Data>
</Path>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</Canvas>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</UserControl>
해결책을 찾을 수 있을까요?