次のシナリオがあります。ItemsControlを含むウィンドウがあります。私は、WindowのDataContextのViewModelを指定します。 ItemControlのItemTemplateのDataTemplateを指定します。 DataTemplateではComboBoxを使用し、ComboBoxのItemsSourceにはRelativeSourceバインディングを含むウィンドウのDataContextを使用します。実行時にはすべて正常に動作し、バインディングは正しく解決されますが、Design-Time CiderではItemSourceがバインドされているウィンドウのViewModelを取り出すことができません。ここでWpf RelativeSourceを使用するバインディングブレンドのブレンド性
は(私が一番上にあるXML名前空間宣言を残したが、私のコードでは、それらが含まれている)私のコードです:
<Window d:DataContext="{Binding Source={StaticResource DesignViewModel}}">
<Window.Resources>
<designviewmodels:GenresEditorDesignViewModel x:Key="DesignViewModel" />
</Window.Resources>
<ItemsControl Grid.Row="0" Margin="3" ItemsSource="{Binding Path=CurrentState}" >
<ItemsControl.ItemTemplate>
<DataTemplate>
<Grid DataContext="{Binding}">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"></ColumnDefinition>
<ColumnDefinition Width="20"></ColumnDefinition>
</Grid.ColumnDefinitions>
<ComboBox Grid.Column="0" Margin="3,0,3,0"
ItemsSource="{Binding RelativeSource={RelativeSource Mode=FindAncestor,
AncestorType={x:Type Window}}, Path=DataContext.AvailableGenres,
Mode=OneWay}"
DisplayMemberPath="Name"
SelectedItem="{Binding Path=Genre, Mode=TwoWay}" DataContext="
{Binding}" />
</Grid>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</Window>
だから、基本的には上記のコード片からのパス= DataContext.AvailableGenresは、設計時には解決できませんが、実行時には正しく解決されます。
私が何か間違っているのか、それとも設計時にRelativeSourcesへのバインディングを解決できないWpf xamlパーサに問題があるのか誰かが知っていますか?
...ブレンド可能性? –
デザインタイムデータを作成する機能は、デザイナーが に対抗するものです... – Imri