1
<TextBox Grid.Column="2"  Height="25"   IsReadOnly="True" TextAlignment="Right"  Text="{Binding ElementName=Mygroups, TargetNullValue= 'C:\myfolder1\mysubfolder1',Path=DataContext.FoldernameWithPath,UpdateSourceTrigger=PropertyChanged,Mode=TwoWay}"  />
<Button Grid.Column="3" Grid.Row="1"  Content="Browse"    Height="25" VerticalAlignment="Bottom"   MinWidth="47"   Command="{Binding ElementName=Mygroups,Path=DataContext.OpenFolderCommand}" CommandParameter="{Binding}" />

Before the user clicks the browse button,I need to bind the Textbox with default folderpath which is mentioned in TargetNullValue. But in my case it is binding like this C:myfolder1mysubfolder1

What I should do to bind the textbox like C:\myfolder1\mysubfolder1 ?

GJPD
  • 89
  • 1
  • 9

1 Answers1

1

I don't know what is the reason but adding another '\' seems to work:

<TextBox Grid.Column="2"  Height="25"   IsReadOnly="True" TextAlignment="Right"  Text="{Binding ElementName=Mygroups, TargetNullValue= 'C:\\myfolder1\\mysubfolder1',Path=DataContext.FoldernameWithPath,UpdateSourceTrigger=PropertyChanged,Mode=TwoWay}"  />
<Button Grid.Column="3" Grid.Row="1"  Content="Browse"    Height="25" VerticalAlignment="Bottom"   MinWidth="47"   Command="{Binding ElementName=Mygroups,Path=DataContext.OpenFolderCommand}" CommandParameter="{Binding}" />
itaiy
  • 1,152
  • 1
  • 13
  • 22
  • yeah...Thank you – GJPD Jan 23 '19 at 09:07
  • 1
    The reason is that XAML strings are like normal C# strings. The backslash is the [escape character](https://learn.microsoft.com/en-us/dotnet/csharp/programming-guide/strings/) of C# strings. The most common one is ``\n``. If one wants to print a backslash deliberately, he should do ``\\``, like in your solution! – OnZi12 Jul 28 '21 at 07:27