I have a loop (about 30 iterations) in which I call a function that creates a new Polyline object:
private Polyline MakeArrow() { Polyline pl = new Polyline(); pl.Style = Resources["ClosedTheme_Arrow"] as Style; return pl; } The problem is that the style is assigned only to the first element.
If you move the style from XAML directly into behind-code , then everything works as it should:
private Polyline MakeArrow() { Polyline pl = new Polyline(); //pl.Style = Resources["ClosedTheme_Arrow"] as Style; Windows.UI.Xaml.Media.PointCollection pc = new Windows.UI.Xaml.Media.PointCollection(); pc.Add(new Windows.Foundation.Point(0, 0)); pc.Add(new Windows.Foundation.Point(4, 5)); pc.Add(new Windows.Foundation.Point(0, 10)); pl.Points = pc; pl.Stroke = new Windows.UI.Xaml.Media.SolidColorBrush(Windows.UI.Colors.White); return pl; } Of course, you can also leave the second option, you just want to understand why in the first case the program behaves so implicitly (from my point of view).
XAML style code:
<Style x:Key="ClosedTheme_Arrow" TargetType="Polyline"> <Setter Property="Points" Value="0,0 4,5 0,10"/> <Setter Property="Stroke" Value="#fff"/> </Style> By the method of "scientific spear" it turned out that the problem is in this line of style:
<Setter Property="Points" Value="0,0 5,4 10,0"/> It is she who is assigned only to the first element. Or dumps all the elements in one place and it seems that only one element is visible.
Resources["ClosedTheme_Arrow"]look like? - Maepl.Style = new Resources["ClosedTheme_Arrow"]? - Mae