views:

948

answers:

2

I'm having a problem with this this XAML... When I run it, it hangs because of the TextBox. (By "hangs" I mean that the hosting aspx page shows in the browser, but the usercontrol object will not appear on the page, and there are some little green bars in the bottom of the Internet Explorer window that fill up but never go away.) I have both a TextBox and a TextBlock in my code just for testing. It runs fine if I comment out the TextBox and leave only the TextBlock, so I know the DataContext is getting set and the binding to PatternName does work. There are no errors in the Output window to help me debug. Please help! I've spent hours on this problem. What can possible be happening?

    <StackPanel x:Name="HolePatternStackPanel" >
            <TextBlock Text="{Binding PatternName}" Width="75" />
            <TextBox Text="{Binding PatternName}" Height="25" Width="125"/>
     </StackPanel>

Here is the code that sets the DataContext from a calling ListBox.SelectionChanged method:

private void lvHolePatterns_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
    HolePatternStackPanel.DataContext = this.ActivePattern;
}
A: 

Well, I've learned more about this... This whole thing is a Master-Detail UI design, and so I had my ListBox using SelectedItem="{Binding ActivePattern}", and apparently, some infinite loop was getting set up between that and the SelectionChanged eventhandler.

So now my question now becomes what good is SelectedItem anyway? Since I had to add a SelectionChanged eventhandler to update the DataContext of the detail stack panel?

MattSlay
A: 

You wouldn't need to use the SelectionChanged event if you set the DataContext of the controls with the SelectedItem

for example

<Grid DataContext="{Binding SelectedItem}">
  <TextBlock Text="{Binding some_field_in_selecteditem}" />
</Grid>
jdiaz