ConventionManager configuration for code-behind dependency properties

Topics: Conventions, Getting Started
Feb 3, 2013 at 9:05 PM
Hello!

I'm pretty new to CM and probably my problem is rather simple to be solved, but I'm googleing for it since hours and can't find a solution.

I've defined a ContentControl to encapsulate parts of my XAML. The content control looks more or less like the following:
<ContentControl x:Class="Momokko.Views.ListEditorContentControlView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:local="clr-namespace:Momokko.Views"
             xmlns:system="clr-namespace:System.Collections;assembly=mscorlib"
             mc:Ignorable="d">


    <Grid/>
</ContentControl>
In my code-behind file, I've defined a dependency property that I will need later:
    public partial class ListEditorContentControlView : ContentControl
    {
   
     public readonly static DependencyProperty ColumnsProperty = DependencyProperty.Register("Columns", typeof(ObservableCollection<String>), typeof(ListEditorContentControlView));
        public ObservableCollection<String> Columns
        {
            get { return (ObservableCollection<String>)GetValue(ColumnsProperty); }
            set { SetValue(ColumnsProperty, value); }
        }

        public ListEditorContentControlView()
        {
            SetValue(ColumnsProperty, new ObservableCollection<String>());

            InitializeComponent();
        }
}
My ViewModel looks like the following:
    public class ListEditorContentControlViewModel : ValidatingScreen<ListEditorContentControlViewModel>
    {
        public ObservableCollection<String> Columns { get; set; }
    }
Now my question is, how must the ConventionManager.AddElement looks like, to get the automatic binding working? The following doesn't work :-(
ConventionManager.AddElementConvention<Momokko.Views.ListEditorContentControlView>(Momokko.Views.ListEditorContentControlView.ColumnsProperty, "Columns", "ColumnsChanged");
Best regards and thank you for your help!

Rufus
Feb 19, 2014 at 1:19 PM
Did you find a solution Rufus?

I have a similar issue,
I am adapting a project with views and viewmodels not written with Caliburn in mind, and it has dependency properties in the code behind. How do I get the automatic binding to work appropriately for code behind dependency properties?

Thanks,
Jeroen.
Feb 19, 2014 at 2:17 PM
Hello Jeroen!

I'm very sorry, but I didn't find a solution - finally I changed the whole architecture.

Best regards

Rufus