简体   繁体   中英

WPF seemingly super-simple dependency property

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!

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM