I have a UserControl with the following properties:
Public Shared ReadOnly IndexProperty As DependencyProperty = DependencyProperty.Register("Index", GetType(Integer), GetType(BoardSquare), New PropertyMetadata(0))
Public Shared ReadOnly SidesProperty As DependencyProperty = DependencyProperty.Register("Sides", GetType(TravelType()), GetType(BoardSquare), New PropertyMetadata({TravelType.None, TravelType.None, TravelType.None, TravelType.None}, AddressOf SidesIsOverpassChanged))
Public Shared ReadOnly IsOverpassProperty As DependencyProperty = DependencyProperty.Register("IsOverpass", GetType(Boolean), GetType(BoardSquare), New PropertyMetadata(False, AddressOf SidesIsOverpassChanged))
Public Property Index As Integer
Get
Return CInt(GetValue(IndexProperty))
End Get
Set(ByVal value As Integer)
SetValue(IndexProperty, value)
End Set
End Property
Public Property Sides() As TravelType()
Get
Return CType(GetValue(SidesProperty), TravelType())
End Get
Set(ByVal value As TravelType())
SetValue(SidesProperty, value)
End Set
End Property
Public Property IsOverpass() As Boolean
Get
Return CBool(GetValue(IsOverpassProperty))
End Get
Set(ByVal value As Boolean)
SetValue(IsOverpassProperty, value)
End Set
End Property
And in my code I attempt to assign values to ItemsControl.ItemsSource as follows:
Dim originalsquaresides As (Sides As TravelType(), IsOverpass As Boolean)() = {
({TravelType.None, TravelType.None, TravelType.None, TravelType.None}, False),
({TravelType.Road, TravelType.Road, TravelType.None, TravelType.None}, False),
({TravelType.Road, TravelType.Road, TravelType.Road, TravelType.Road}, False),
({TravelType.Road, TravelType.Track, TravelType.Road, TravelType.Track}, True),
({TravelType.Track, TravelType.None, TravelType.None, TravelType.Road}, False),
({TravelType.None, TravelType.None, TravelType.None, TravelType.None}, False)}
Me.itmSquares.ItemsSource = originalsquaresides.Zip(Enumerable.Range(0, originalsquaresides.Length), Function(square, index) New With {.Sides = square.Sides, .IsOverpass = square.IsOverpass, .Index = index})
And my XAML includes the following ItemsControl:
<ItemsControl x:Name="itmSquares" HorizontalAlignment="Center" VerticalAlignment="Center">
<ItemsControl.ItemsPanel><ItemsPanelTemplate><VariableSizedWrapGrid Orientation="Horizontal" MaximumRowsOrColumns="7"/></ItemsPanelTemplate></ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate><DataTemplate><ctrl:BoardSquare Sides="{Binding Sides,Mode=TwoWay}" IsOverpass="{Binding IsOverpass,Mode=TwoWay}" Index="{Binding Index,Mode=TwoWay}" AllowDrop="True" DragEnter="BoardSquare_DragEnter" Drop="BoardSquare_Drop" DragLeave="BoardSquare_DragLeave" SquareChanged="BoardSquare_SquareChanged"/></DataTemplate></ItemsControl.ItemTemplate>
</ItemsControl>
However, when I do this, all of the Sides is set correctly for all elements, but IsOverpass is not set for anything, and Index is only set for the last element. Why is this, and how can I fix it? Thanks.