모양 모음에 어떻게 바인딩하나요?셰이프 컬렉션에 바인딩?
셰이프를 그릴 때 MVVM을 사용하는 작은 응용 프로그램을 (단지 학습 목적으로) 구축하고 싶습니다.
는 MainWindow를의 DataContext를는 MainWindowViewModel
MainWindowViewModel 도형의 ObservableCollection에이 있는지이다. 나는이 같은 사각형을 추가
<Window x:Class="DesktopCanvas.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
>
<Canvas DataContext="{Binding Source=ShapeCollection}">
</Canvas>
</Window>
을 MainWindowViewModel의 생성자에서 :
나는 작동하지 않는 컬렉션에 바인딩의 DataContext에 내 MainWindow를에 현재는 캔버스를
this.ShapeCollection = new ObservableCollection<Shape>();
Rectangle rect = new Rectangle();
//Größe
rect.Height = 75;
rect.Width = 75;
//Transparenz
rect.Opacity = 100;
//Farbe
SolidColorBrush myBrush = new SolidColorBrush(Colors.Red);
rect.Fill = myBrush;
this.ShapeCollection.Add(rect);
아니요 지금까지 바인딩 오류가 없습니다. 어떤 아이디어?