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.