Wednesday, October 31, 2012

Silverlight5 - Binding breakpoint not hit in ItemsControl

Silverlight5 - Binding breakpoint not hit in ItemsControl

Using VS2012 and SL5.

When I set a breakpoint on the Content={Binding} and hit debug, the code works, but the breakpoint is never hit. Why?

Have tried restarting studio (this works when I sometimes can't set a red dot breakpoint in code).

<Grid Grid.Row="5">     <ItemsControl>         <ItemsControl.Items>             <Button Content="First" />             <Rectangle Width="20" Height="20" />             <Button Content="Second" />             <Rectangle Width="20" Height="20" />             <Button Content="Third" />         </ItemsControl.Items>          <ItemsControl.ItemsPanel>             <ItemsPanelTemplate></ItemsPanelTemplate>         </ItemsControl.ItemsPanel>          <ItemsControl.ItemTemplate>             <DataTemplate>                 <Button Content="{Binding}" />             </DataTemplate>         </ItemsControl.ItemTemplate >     </ItemsControl> </Grid> 

enter image description here

Answers & Comments...

Answer: 1

I think I know why it didn't hit... no default binding has been setup. This works below on the binding breakpoints.

<Grid Grid.Row="5">     <!-- bind to the Data property of element AccountsDataSourceT32 -->     <ItemsControl ItemsSource="{Binding Data, ElementName=AccountsDataSourceT32}">         <ItemsControl.ItemsPanel>             <ItemsPanelTemplate></ItemsPanelTemplate>         </ItemsControl.ItemsPanel>          <ItemsControl.ItemTemplate>             <DataTemplate>                 <Button Content="{Binding Username}" />             </DataTemplate>         </ItemsControl.ItemTemplate >     </ItemsControl> </Grid> 
by : Dave Mateerhttp://stackoverflow.com/users/26086




No comments:

Post a Comment

Send us your comment related to the topic mentioned on the blog