WPF seemingly super-simple dependency property

北城余情 提交于 2019-12-12 05:13:27

问题


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();
        }

    }
}   

This is the actual 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>

This is the error I'm getting:

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!


回答1:


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



来源:https://stackoverflow.com/questions/2095868/wpf-seemingly-super-simple-dependency-property

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!