一个“>”导致我调试了1个小时才解决问题
在XAML里面写了如下的代码:
<DataTemplate x:Key="DT_HintCategory"> <Expander HorizontalContentAlignment="Stretch" ExpandDirection="Down" Expanded="Expander_Expanded" Header="AAA" IsExpanded="{Binding Path=IsExpanded, Mode=TwoWay}"> <Expander.Content> <ListBox x:Name="PART_HINTS" IsSynchronizedWithCurrentItem="False">> <ListBox.ItemsSource> <PriorityBinding> <Binding Path="HintsSlow" IsAsync="True" /> <Binding Path="HintsFast" IsAsync="False" /> </PriorityBinding> </ListBox.ItemsSource> <ListBox.ItemTemplate> <DataTemplate> <StackPanel> <TextBlock Text="{Binding Name}" /> </StackPanel> </DataTemplate> </ListBox.ItemTemplate> </ListBox> </Expander.Content> </Expander> </DataTemplate>
原因就是: <ListBox x:Name="PART_HINTS" IsSynchronizedWithCurrentItem="False">>(多写了一个大于号!)
结果在设计界面显示:An Unhandled Exception has occured: Click here to reload the designer.
在调试过程中,报:
{"Add value to collection of type 'System.Windows.Controls.ItemCollection' threw an exception."}
Inner Exception: {"Operation is not valid while ItemsSource is in use. Access and modify elements with ItemsControl.ItemsSource instead."}