I'm working on a graph program that shows different datas in wpf. I want to bind Canvas Drawings to vertices. I have nearly the same problem like in Binding WPF Canvas Children to an ObservableCollection .
(first question): I want to Convert my Path Data (see XAML) into a Geometry. How?!
(second question): I want to Bind theese Paths to "Something" (ItemsControl) and show them.
I can show Canvas data by writing it directly into XAML:
<Viewbox>
<Grid
VerticalAlignment="Center"
HorizontalAlignment="Left">
<Grid.RenderTransform>
<TransformGroup>
<ScaleTransform ScaleX="8.0" ScaleY="8.0"></ScaleTransform>
<TranslateTransform X="-50" Y="0"/>
</TransformGroup>
</Grid.RenderTransform>
<Path
Data="M 8.8733,6.4011 C 8.8733,5.3196 7.9235,4.4428 6.7518,4.4428 C 5.5802,4.4428 4.6304,5.3196 4.6304,6.4011 C 4.6304,7.4826 5.5802,8.3594 6.7518,8.3594 C 7.9235,8.3594 8.8733,7.4826 8.8733,6.4011 Z ">
<Path.Fill>
<SolidColorBrush Color="#FFFFFFFF"/>
</Path.Fill>
</Path>
<Path
Data="M 8.8733,6.4011 C 8.8733,5.3196 7.9235,4.4428 6.7518,4.4428 C 5.5802,4.4428 4.6304,5.3196 4.6304,6.4011 C 4.6304,7.4826 5.5802,8.3594 6.7518,8.3594 C 7.9235,8.3594 8.8733,7.4826 8.8733,6.4011 Z "
Stroke="#FF000000" StrokeThickness="0.72" StrokeStartLineCap="Round"
StrokeEndLineCap="Round" StrokeDashCap="Round" StrokeLineJoin="Round">
</Path>
</Grid>
</Viewbox>
But I want to change it according to vertex types.
<ItemsControl ItemsSource="{Binding CanvasVecPicture}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<Canvas />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>
My Vertex class:
...
private ObservableCollection<Shape> canvasVecPicture;
public ObservableCollection<Shape> CanvasVecPicture { get { return canvasVecPicture; } }
...
Path myPath = new Path();
myPath.Stroke = System.Windows.Media.Brushes.Black;
myPath.Fill = System.Windows.Media.Brushes.MediumSlateBlue;
myPath.StrokeThickness = 100;
myPath.HorizontalAlignment = HorizontalAlignment.Left;
myPath.VerticalAlignment = VerticalAlignment.Center;
EllipseGeometry myEllipseGeometry = new EllipseGeometry();
myEllipseGeometry.Center = new System.Windows.Point(0, 0);
myEllipseGeometry.RadiusX = 2000;
myEllipseGeometry.RadiusY = 2000;
myPath.Data = myEllipseGeometry;
Ellipse ellipse = new Ellipse();
SolidColorBrush brush = new SolidColorBrush(Brushes.Blue.Color);
ellipse.Fill = brush;
ellipse.StrokeThickness = 2;
ellipse.Stroke = Brushes.Black;
ellipse.Width = 100;
ellipse.Height = 100;
canvasVecPicture = new ObservableCollection<Shape>();
canvasVecPicture.Add(myPath);
canvasVecPicture.Add(ellipse);
In debugger the "get" method called lots of time, so I don't think it is a Binding Problem.