私はVisual Studio拡張機能を書いていますが、これは関連性がないと思われますが、おそらくそうです。私のコードは、initializeComponentが呼び出されているときにコードビハインドに例外をスローしています。私は "モデル"を作成し、それをコンストラクタのSectionView(xaml)に渡すTeamExplorerSectionを持っています。これはビューのプロパティとして保存されます。モデルには、名前、IDなどのプロパティがあります。これらのプロパティをビューにバインドできますが、スタックパネルにあるItemsControlにバインドしようとしているコレクションもあります。これは動作しません。Visual Studioの拡張機能であるスタックパネルでバインディングを行うにはどうすればよいですか?
System.Windows.Markup.XamlParseException発生 HRESULT = 0x80131501 メッセージ= 'タイプのコレクションに値を追加' System.Windows.Controls:ここ
は例外です.ItemCollection 'が例外をスローしました。行番号「22」および行位置「19」。 ソース= PresentationFramework のStackTrace:System.Windows.Markup.WpfXamlLoader.LoadBamlでSystem.Windows.Markup.WpfXamlLoader.Load(XamlReader xamlReader、IXamlObjectWriterFactory writerFactory、ブールskipJournaledProperties、rootObject、XamlObjectWriterSettings設定、ウリBASEURIオブジェクト) (XamlReaderで System.Windows.Application.LoadComponent(System.Windows.Application.LoadComponent)内の (System.Windows.Markup.XamlReader.LoadBaml)(ストリームストリーム、ParserContext parserContext、Object親、ブールcloseStream) 、Uri resourceLocator) at ReviewPlus.TeamExplorerSectionView.InitializeComponent()in C:\ Dev \ ReviewPlus \ ReviewPlus \ CodePlusTeamExplorerSectionView.xaml:line 1 内部例外1: InvalidOperationException:ItemsSourceの使用中に操作が無効です。代わりにItemsControl.ItemsSourceを使用して要素にアクセスして変更してください。<UserControl x:Class="ReviewPlus.ReviewPlusTeamExplorerSectionView" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:ReviewPlus.ViewModels="clr-namespace:ReviewPlus.ViewModels" mc:Ignorable="d" d:DesignHeight="250" d:DesignWidth="300"> <UserControl.DataContext> <ReviewPlus.ViewModels:RelatedReviewsViewModel/> </UserControl.DataContext> <StackPanel> <ItemsControl Name="RelatedReviewsICtl" ItemsSource="{Binding RelatedReviews}"> <DataTemplate> <StackPanel Orientation="Horizontal" HorizontalAlignment="Left"> <TextBlock Text="{Binding Path=Name}" /> <TextBlock Text="{Binding Path=PreviousId}"/> <TextBlock Text="{Binding Path=Id}"/> </StackPanel> </DataTemplate> </ItemsControl> </StackPanel>
私はこのバインディングに間違っているようです。