WPF似乎超级简单的依赖项属性 [英] WPF seemingly super-simple dependency property
问题描述
我很困惑。我正在尝试创建一个名为 TranslationView
的用户控件。它几乎完全由一个 ListView
组成。我现在不认为这很重要,因为我什至无法编译我的代码隐藏。
I'm puzzled. I'm trying to create a user control called TranslationView
. It consists pretty much entirely of a single ListView
. I don't think that's important now however, because I cannot even compile my code-behind.
这是代码的隐藏用户控制:
This is the code-behind for the user control:
namespace Subster
{
/// <summary>
/// Interaction logic for TranslationView.xaml
/// </summary>
public partial class TranslationView : UserControl
{
// Generated using "propdp" in Visual Studio 2008.
public ObservableCollection<TransRowOrig> TranslationSource
{
get { return (ObservableCollection<TransRowOrig>)GetValue(TranslationSourceProperty); }
set { SetValue(TranslationSourceProperty, value); }
}
// Generated using "propdp" in Visual Studio 2008.
public static readonly DependencyProperty TranslationSourceProperty =
DependencyProperty.Register("TranslationSource",
typeof(ObservableCollection<TransRowOrig>),
typeof(TranslationView));
public TranslationView()
{
InitializeComponent();
}
}
}
这是实际的XAML:
<UserControl x:Class="Subster.TranslationView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Grid>
<ListView Grid.Row="1" ItemsSource="{Binding Path=TranslationSource}">
<ListView.View>
<GridView>
<GridView.Columns>
<GridViewColumn Header="Start time"/>
<GridViewColumn Header="End time"/>
<GridViewColumn Header="Duration"/>
<GridViewColumn Header="Original"/>
<GridViewColumn Header="Translation"/>
</GridView.Columns>
</GridView>
</ListView.View>
</ListView>
</Grid>
</UserControl>
这是我得到的错误:
可访问性不一致:属性类型'System.Collections.ObjectModel.ObservableCollection'的访问权限比属性'Subster.TranslationView.TranslationSource'少。
Inconsistent accessibility: property type 'System.Collections.ObjectModel.ObservableCollection' is less accessible than property 'Subster.TranslationView.TranslationSource'.
对我来说毫无意义,因为我发现的所有示例都以类似的方式工作!我什至没有在项目的任何其他部分中使用用户控件。
It makes no sense at all to me, because all of the examples I've found work in similar ways! I don't even use the user control in any other part of the project yet.
任何帮助我们都表示赞赏!
Any help highly appreciated!
推荐答案
您的 TransRowOrig
对象很可能无法访问,因此该类定义为公共类
。因此,我将 TransRowOrig
设为公开课程
Most likely your TransRowOrig
object is less accessible then this class which is defined as a public class
. So I'd make that TransRowOrig
also a public class
这篇关于WPF似乎超级简单的依赖项属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!