Search code examples
c#wpfbindingtargetnullvalue

How to set TargetNullValue as folderpath in binding?


<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 ?


Solution

  • 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}" />