I generate a list of elements with an ObservableList
and an ItemsControl
.
But I need to know the ActualWidth
of the single controls with reference to the bound item in the list.
I need the Width
to cut down my Polyline
so that it is no longer than the Canvas
I tried a OneWayToSource
and a TwoWay
Binding back to the Item in the List with the Width
Property. Always got NaN or 0.
<ItemsControl x:Name="GraphLB" ItemsSource="{Binding}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<Border Padding="5, 0, 5, 0">
<StackPanel>
<TextBlock Text="{Binding Text}" Foreground="{Binding Foreground}"/>
<Border BorderBrush="{Binding Foreground}" BorderThickness="0.5">
<Canvas MinHeight="40" MinWidth="100"
Height="{Binding Height, Mode = TwoWay }"
Width="{Binding Width, Mode = TwoWay }">
<Polyline Points="{Binding Line}" Stroke="{Binding Foreground}" StrokeThickness="1"/>
</Canvas>
</Border>
</StackPanel>
</Border>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
And the Class for the Bound Objects
class GraphListObject : LabelListObject
{
public double Height { get; set; }
public double Width { get; set; }
private getProperty<PointCollection> getLine;
public PointCollection Line { get { return GetLine(); } }
internal getProperty<PointCollection> GetLine { get => getLine; set { getLine = value; } }
}
I expected that the Width="{Binding Width, Mode = TwoWay }"
would set the Value in the Element of the List to the Width of the Canvas
Element, but the actual output is 0.
Sadly the Polyline
is drawn outside the borders: