안녕하세요.
작업하다 생각지도 못한 문제가 발생해서요…
문제상황
-
TrulyObservableCollection Lines라는 컬랙션 객체안에
PointCollection이 있습니다. 그래서 PointCollection 객체 하나 만으로 선을 만들 수 있습니다. -
그런데, 문제는 Poly라인이 따로 따로 만들어져야되는데 Poly라인의 끝과 끝이 서로 연결되는 문제가 있습니다.
제가 원하는 방식은 아래 이미지와 같습니다.
문제가 발생한 상황
CanvasGroupView.xaml
<ItemsControl ItemsSource="{Binding Lines, UpdateSourceTrigger=PropertyChanged}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<Canvas />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<Canvas>
<Polyline Points="{Binding LinePoints,UpdateSourceTrigger=PropertyChanged}"
StrokeThickness="15.0"
Stroke="LawnGreen" />
<ItemsControl ItemsSource="{Binding LinePoints, UpdateSourceTrigger=PropertyChanged}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<Canvas />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<Path StrokeThickness="2.0"
Stroke="Black"
Fill="LawnGreen">
<Path.Data>
<EllipseGeometry Center="{Binding}"
RadiusX="8"
RadiusY="8" />
</Path.Data>
</Path>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</Canvas>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
LinePointViewModel.cs
public class LinePointViewModel
: INotifyPropertyChanged
{
public LinePointViewModel()
{
_linePoints = new PointCollection();
}
private PointCollection _linePoints;
public event PropertyChangedEventHandler PropertyChanged;
public PointCollection LinePoints
{
get { return _linePoints; }
set
{
_linePoints = value;
RaisePropertyChanged("LinePoints");
}
}
private void RaisePropertyChanged(string propertyName)
{
// take a copy to prevent thread issues
PropertyChangedEventHandler handler = PropertyChanged;
if (handler != null)
{
handler(this, new PropertyChangedEventArgs(propertyName));
}
}
}
CanvasGroupViewModel.cs
public class CanvasGroupViewModel
: CanvasEntityViewModel<SymbolGroupProvider>
{
public CanvasGroupViewModel(SymbolGroupProvider entityProvider, bool visibility = true) : base(entityProvider, visibility)
{
Lines = new TrulyObservableCollection<LinePointViewModel>();
_groupProvider = IoC.Get<GroupProvider>();
}
public void CreateLines(int mapNumber)
{
try
{
Lines.Clear();
var mappedGroups = _groupProvider.Where(t => t.Map == mapNumber);
var pointCollection = new PointCollection();
foreach (var group in mappedGroups)
{
foreach (var entity in EntityProvider)
{
if(entity.NameArea == group.NameArea)
pointCollection.Add(new Point(entity.X1, entity.Y1));
}
if (pointCollection.Count() > 0)
{
var line = new LinePointViewModel();
line.LinePoints = pointCollection;
Lines.Add(line);
}
}
}
catch (Exception ex)
{
Debug.WriteLine($"Exception Rasied in CreateLines : {ex.Message}");
}
}
public TrulyObservableCollection<LinePointViewModel> Lines
{
get { return _lines; }
set
{
_lines = value;
NotifyOfPropertyChange(()=>Lines);
}
}
private GroupProvider _groupProvider;
private TrulyObservableCollection<LinePointViewModel> _lines;
}
}
제가 예상하기로는 Xaml쪽만 수정하면 될 것같은데,
어떻게 접근하면 좋을까요??