Windows Phone app: Binding data in a UserControl which is contained in a ListBox

Posted by Alexandros Dafkos on Stack Overflow See other posts from Stack Overflow or by Alexandros Dafkos
Published on 2012-10-17T20:00:58Z Indexed on 2012/10/17 23:01 UTC
Read the original article Hit count: 329

I have an "AddressListBox" ListBox that contains "AddressDetails" UserControl items, as shown in the .xaml file extract below. The Addresses collection is defined as

ObservableCollection< Address > Addresses

and Street, Number, PostCode, City are properties of the Address class. The binding fails, when I use the "{Binding property}" syntax shown below. The binding succeeds, when I use the "dummy" strings in the commented-out code. I have also tried "{Binding Path=property}" syntax without success. Can you suggest what syntax I should use for binding the data in the user controls?

        <ListBox x:Name="AddressListBox"

                 DataContext="{StaticResource dataSettings}" ItemsSource="{Binding Path=Addresses, Mode=TwoWay}">
            <ListBox.ItemTemplate>
                <DataTemplate>
                    <!--
                    <usercontrols:AddressDetails AddressRoad="dummy" AddressNumber="dummy2" AddressPostCode="dummy3" AddressCity="dummy4">
                    </usercontrols:AddressDetails>
                    -->

                    <usercontrols:AddressDetails AddressRoad="{Binding Street}" AddressNumber="{Binding Number}" AddressPostCode="{Binding PostCode}" AddressCity="{Binding City}">
                    </usercontrols:AddressDetails>

                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>

© Stack Overflow or respective owner

Related posts about data-binding

Related posts about usercontrols