Собственность привязки WPF в USERCONTROL

У меня есть пользовательский USERCONTROL, который содержит коллекцию пользовательских объектов.

public class Question : FrameworkElement
{
    public readonly static DependencyProperty FullNameProperty =
        DependencyProperty.Register("FullName", typeof(string), typeof(Question));

    public readonly static DependencyProperty ShortNameProperty =
        DependencyProperty.Register("ShortName", typeof(string), typeof(Question));

    public readonly static DependencyProperty RecOrderProperty =
        DependencyProperty.Register("RecOrder", typeof(int), typeof(Question));

    public readonly static DependencyProperty AnswerProperty =
        DependencyProperty.Register("Answer", typeof(string), typeof(Question));

    public string FullName
    {
        get { return (string)GetValue(FullNameProperty); }
        set { SetValue(NameProperty, value); }
    }

    public string ShortName
    {
        get { return (string)GetValue(ShortNameProperty); }
        set { SetValue(ShortNameProperty, value); }
    }

    public string Answer
    {
        get { return (string)GetValue(AnswerProperty); }
        set { SetValue(AnswerProperty, value); }
    }

    public int RecOrder
    {
        get { return (int)GetValue(RecOrderProperty); }
        set { SetValue(RecOrderProperty, value); }
    }
}

В моем контрольном коде-позади у меня есть

public readonly static DependencyProperty QuestionsProperty =
        DependencyProperty.Register("Questions", typeof(ObservableCollection<Question>), typeof(FormQuestionReportViewer), 
        new PropertyMetadata(new ObservableCollection<Question>()));


     public ObservableCollection<Question> Questions
     {
        get { return GetValue(QuestionsProperty) as ObservableCollection<Question>; }
        set { SetValue(QuestionsProperty, value); }
     }

, а в Markup

public readonly static DependencyProperty QuestionsProperty =
        DependencyProperty.Register("Questions", typeof(ObservableCollection<Question>), typeof(FormQuestionReportViewer), 
        new PropertyMetadata(new ObservableCollection<Question>()));


     public ObservableCollection<Question> Questions
     {
        get { return GetValue(QuestionsProperty) as ObservableCollection<Question>; }
        set { SetValue(QuestionsProperty, value); }
     }

и в XAML Markup я могу определить мой контроль, как это

    <custom:CustomControl>
        <custom:CustomControl.Questions>
            <custom:Question FullName="smth text" ShortName="smth text" RecOrder="1" Answer="Yes" />
            <custom:Question FullName="smth text" ShortName="smth text" RecOrder="2" Answer="Yes" />
        </custom:CustomControl.Questions>          
    </custom:CustomControl>

, это работает хорошо, но я хочу сделать привязку моей коллекции в XAML, как это

    <custom:CustomControl>
        <custom:CustomControl.Questions Items="{binding Path=Questions}">
            <custom:Question FullName="{binding Name}" ShortName="{binding ShortName}" RecOrder="{binding RecOrder}" Answer={binding Answer}" /> 
        </custom:CustomControl.Questions>          
    </custom:CustomControl>

Как я Может сделать это связывание?

6
задан CodeNaked 6 September 2011 в 14:54
поделиться