I'm developing a WPF application using the MVVM pattern. In my application I have a canvas that is supposed to display several different shapes. These shapes describe a warehouse (a.k.a storage) and the warehouse contents.
To display only the warehouse (which is described by a ObservableCollection<Point>
) I use the following code snippet
<Canvas Width="{Binding StorageWidth, Mode=OneWay}" Height="{Binding StorageHeight, Mode=OneWay}">
<Polygon Points="{Binding StorageVertices, Mode=OneWay, Converter={StaticResource PointCollectionConverter}}" Stroke="Gray" StrokeThickness="30">
<Polygon.Fill>
<SolidColorBrush Color="DarkRed" Opacity="0.25" />
</Polygon.Fill>
</Polygon>
</Canvas>
To this canvas, I want to add rectangles (for describing offices within the storage) and circles (to describe nodes within the storage). These are defined in my view model:
class Node
{
// ...
Point Position { get; private set; }
}
class Office
{
// ...
ObservableCollection<Point> Vertices { get; private set; }
}
public class ViewModel : ViewModelBase
{
// ...
ObservableCollection<Node> Nodes { get; private set; }
ObservableCollection<Office> Offices { get; private set; }
ObservableCollection<Point> StorageVertices { get; private set; } // Already displayed on the canvas
}
How can I display these on the canvas, alongside with the storage area by using data bindings? I know that I could have used ItemsControl
normally, but now I have several different collections/sources and they are supposed to be described in different ways (Node
s are Circle
s whilst Office
s are Rectangle
s).