Binding user controls

Nov 19, 2011 at 11:12 PM

Hi,

I'm new to CM, so this question is a bit basic.   I have a user control, "FolderSelectionControl" with a textbox and a button that opens a WinForm folder diaogue. The folder path is shown in the textbox. 

 

[ContentProperty("DirectoryPath")]
    public partial class FolderSelectionControl : System.Windows.Controls.UserControl
    {
        public FolderSelectionControl()
        {
            InitializeComponent();
            pathTextbox.TextChanged +=new TextChangedEventHandler(pathTextbox_TextChanged);
        }

        public static readonly DependencyProperty DirectoryPathProperty = DependencyProperty.Register(
           "DirectoryPath",
           typeof(string),
           typeof(FolderSelectionControl));

        private void pathTextbox_TextChanged(object sender, TextChangedEventArgs e)
        {
            this.DirectoryPath = pathTextbox.Text;
            e.Handled = true;
            if (null != DirectoryPathChanged)
                DirectoryPathChanged(this, EventArgs.Empty);
            
        }

        public event EventHandler<EventArgs> DirectoryPathChanged;

        public string DirectoryPath
        {
            get { return (string)GetValue(DirectoryPathProperty); }
            set { SetValue(DirectoryPathProperty, value); }
        }


        private void Browse_Click(object sender, RoutedEventArgs e)
        {
            FolderBrowserDialog folderDialogue = new FolderBrowserDialog();
            if (!string.IsNullOrWhiteSpace(pathTextbox.Text))
            {
                string directory = pathTextbox.Text;
                if (Directory.Exists(directory))
                {
                    folderDialogue.SelectedPath = directory;
                }
            }
            if (DialogResult.OK != folderDialogue.ShowDialog())
                return;
            pathTextbox.Text = folderDialogue.SelectedPath;
        }

I place this control in a View, and I created a ViewModel. 

<my:FolderSelectionControl cal:Bind.Model="{Binding}" HorizontalAlignment="Stretch" Margin="0,0,0,0" x:Name="DirectoryPicker" VerticalAlignment="Top" />

  public class InputFolderViewModel : PropertyChangedBase
    {
        private string _directoryPicker;
        public string DirectoryPicker
        {
            get
            { return _directoryPicker; }
            set
            { 
                _directoryPicker = value;
                NotifyOfPropertyChange(() => DirectoryPicker);
            }
        }
    }

 

The issue is that CM doesn't bind to the control.   What is missing?

Coordinator
Dec 30, 2011 at 12:05 AM

Hello. If you are using Caliburn.Micro, please post in that forum  http://caliburnmicro.codeplex.com/discussions