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

在用户单击浏览按钮之前,我需要将Textbox与 TargetNullValue 中提到的默认文件夹路径绑定。但在我的情况下,它像这样绑定C:myfolder1mysubfolder1

我应该怎么做才能绑定像C:\myfolder1\mysubfolder1这样的文本框?

4

1 回答 1

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}" />
于 2019-01-23T08:31:07.537 回答