私の問題は、DataGrid の ComboBox の ItemsSource がバインドされていないことです。私のユーザーコントロール:
<UserControl x:Class="MyClass"
x:Name="Root"
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:cal="clr-namespace:Caliburn.Micro;assembly=Caliburn.Micro"
mc:Ignorable="d"
d:DesignHeight="360" d:DesignWidth="757">
データグリッド:
<DataGrid x:Name="Article"
AutoGenerateColumns="False"
SelectionUnit="FullRow"
SelectionMode="Single"
CanUserAddRows="False"
CanUserDeleteRows="True"
Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="4"
Margin="5">
<DataGrid.Columns>
<DataGridTemplateColumn Width="*"
Header="Article">
<DataGridTemplateColumn.CellEditingTemplate>
<DataTemplate>
<ComboBox ItemsSource="{Binding FilteredArticle, ElementName=Root}" IsEditable="True"
cal:Message.Attach="[Event KeyUp] = [Action FindArticlel($source)]" />
</DataTemplate>
</DataGridTemplateColumn.CellEditingTemplate>
</DataGridTemplateColumn>
ElementName=Root と言わなければ、彼は FilteredArticle を Article クラスにバインドしようとします。ElementName=Root と言うと、彼は実行時に次のように言います。
System.Windows.Data Error: 4 : Cannot find source for binding with reference 'ElementName=Root'. BindingExpression:Path=FilteredArticle; DataItem=null; target element is 'ComboBox' (Name=''); target property is 'ItemsSource' (type 'IEnumerable')
FilteredArticle は、ViewModel の BindableCollection です。他のすべてのバインディングは機能しています。ここで何が問題なのですか?Caliburn.Micro の最新の安定バージョンを使用します。