所以我在这里有这个 xaml
<ListBox Grid.Column="1" Grid.Row="1" Background="Transparent" ItemsSource="{Binding Packages}">
<ListBox.ItemTemplate>
<DataTemplate>
<gameManagement:FeedGame DataContext="{Binding}" Package="{Binding Path=/}"></gameManagement:FeedGame>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
和一个DependencyProperty
名为的 UserControlPackage
我要做的就是将该属性设置为列表中的当前项目。我已经在这里待了大约一个小时,不知道我做错了什么。
我上面的当前代码抛出了FirstChanceException
一个
BindingExpression path error: '' property not found on 'current item of collection' ''FeedGame' (Name='Me')'. BindingExpression:Path=/; DataItem='FeedGame' (Name='Me'); target element is 'FeedGame' (Name='Me'); target property is 'Package' (type 'IPackage')
如果您好奇是什么Me
,这是在 UserControl 的 xaml 中,上面的列表框包含在
x:Name="Me"
DataContext="{Binding ElementName=Me}"
这是在FeedGame
public static readonly DependencyProperty PackageProperty = DependencyProperty.Register(
"Package", typeof(IPackage), typeof(FeedGame));
public IPackage Package {
get
{
return (IPackage)this.GetValue(PackageProperty);
//return this.package;
}
set
{
// Setter here never gets called.
if (Equals(value, (IPackage)this.GetValue(PackageProperty)))
{
return;
}
SetValue(PackageProperty,value);
this.OnPropertyChanged("Package");
}
}