0

I have an ArcGIS Pro Addin that I need to get a path to gdb for some processing, I would like to do this but show only gdb name in text box. I have a behaviors class and a viewmodel and a view. I tried catching the name as a property in the behaviors class but I am not getting the value when I bind to a text box to check for output. Here is the browser dialog

namespace BasemapCreator.Behaviors
{
    public class FolderDialogBehavior:Behavior<System.Windows.Controls.Button>
    {

        public void FolderBrowserDialog()
        {


        }
        public string SetterName { get; set; }

        protected override void OnAttached()
        {
            base.OnAttached();
            AssociatedObject.Click += OnClick;
        }
        protected override void OnDetaching()
        {

            AssociatedObject.Click -= OnClick;
        }
        private void OnClick(object sender, RoutedEventArgs e)
        {

            var dialog = new FolderBrowserDialog();
            var result = dialog.ShowDialog();
            if (result == DialogResult.OK && AssociatedObject.DataContext != null)
            {
                var propertyInfo = AssociatedObject.DataContext.GetType().GetProperties(System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public)
                    .Where(p => p.CanRead && p.CanWrite)
                    .First(p => p.Name.Equals(SetterName));

                string dirName = new DirectoryInfo(dialog.SelectedPath).Name;
                FolderName = dirName;
                _fileName = System.IO.Path.GetFileName(dirName);
                FileName = _fileName;
                ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show(FileName.ToString());
                propertyInfo.SetValue(AssociatedObject.DataContext, dialog.SelectedPath, null);
            }
        }
        private string _folderName;
        public string FolderName
        {
            get { return _folderName; }
            set
            {
                if (value != _folderName )
                {
                    _folderName = value;
                    OnPropertyChanged("FolderName");
                }
            }

        }
        private string _fileName;
        public string FileName
        {
            get { return _fileName; }
            set
            {
                if (_fileName != value)
                {
                    _fileName = value;
                    OnPropertyChanged("FileName");
                }
            }

        }
        private string _styleName;
        public string StyleName
        {
            get { return _styleName; }
            set
            {
                if (_styleName != value)
                {
                    _styleName = value;
                    OnPropertyChanged("StyleName");
                }
            }
        }

        private void OnPropertyChanged(string propertyname)
        {
            OnPropertyChanged(new PropertyChangedEventArgs(propertyname));
        }

        public event PropertyChangedEventHandler PropertyChanged;

        private void OnPropertyChanged(PropertyChangedEventArgs args)
        {
            var handler = PropertyChanged;
            if (handler != null)
                handler(this, args);
        }

    }
}

Here is the Binding in the View

<TextBox x:Name="gdbName" HorizontalAlignment="Left" Height="30" Margin="56,29,0,0"  Text="{Binding FolderName, Mode=TwoWay}" VerticalAlignment="Top" Width="282" AllowDrop="True">
        </TextBox>

And in the ViewModel I have the FolderName property

private string _folderName;
        public string FolderName
        {
            get { return _folderName; }
            set
            {
                _folderName = value;
                OnPropertyChanged("FolderName");
            }
        }

everything works but the pathnames are so long that sometimes they are hidden. I would like to show gdb name and pass complete path.

0

Here is the solution that works it was provided to me on another forum,'

Here is the property I created for the short name.

public string ShowName => Path.GetFileName(_name);

Then set it when the full path is passed

private string _name;

public string Name
{
    get { return this._name; }
    set
    {
        SetProperty(ref this._name, value, () => Name);
        SetProperty(ref this._showName, value, () => ShowName);
    }
}

In the viewmodel I have the property as well I also create the Model object so that the values can be passed

public CommonUseWindowViewModel()
{
   DisplayFolderName = new Model();
   Build = new DelegateCommand(ClickedMethod);
}
public event PropertyChangedEventHandler PropertyChanged;
public Model DisplayFolderName { get; set; }
public string Name
{
    get{ return DisplayFolderName.Name; }
    set
       {
         DisplayFolderName.Name = value;
         OnPropertyChanged("Name");
         OnPropertyChanged(nameof(ShowName));
       }
 }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.