任何帮助表示赞赏。我对 WPF 很陌生。我有一个由 xml 文件填充的树视图。选择树视图项目后,我需要它显示在文本框中。I have the treeview inside a popup and I've got it so that when the textbox in question is selected, it will bring up the popup with treeview prompting the user to make a selection on the treeview. 之后,它应该将该树视图选择放回同一个文本框中。这是我的代码:
<TextBox Name="text"
Text="{Binding Path=SelectedItem.name, ElementName=dirTree}"
Style="{StaticResource CustomTextBoxStyle}"
Grid.Column="1"
Margin="47,326,110,140"
TextChanged="text_TextChanged" />
树视图部分:
<Popup PlacementTarget="{Binding ElementName=text}"
VerticalOffset="20"
HorizontalOffset="-180"
Margin="0,0,465,279"
Name="popup1"
AllowsTransparency="True"
Placement="Top">
<Popup.Style>
<Style TargetType="{x:Type Popup}">
<Style.Triggers>
<DataTrigger Binding="{Binding ElementName=text, Path=IsFocused}"
Value="True">
<Setter Property="IsOpen"
Value="True" />
</DataTrigger>
<!--<DataTrigger Binding="{Binding ElementName=popupText, Path=IsFocused}"
Value="True">
<Setter Property="IsOpen"
Value="True" />
</DataTrigger>-->
</Style.Triggers>
</Style>
</Popup.Style>
<Grid>
<Border BorderThickness="2"
Background="DodgerBlue"
BorderBrush="DodgerBlue"
Padding="0"
CornerRadius="6">
<ScrollViewer Height="300"
Name="scrollViewer1"
Width="175"
BorderBrush="Black"
Background="DodgerBlue">
<TreeView Name="dirTree"
ItemsSource="{Binding Source={StaticResource xmldata}, XPath=.}"
VirtualizingStackPanel.IsVirtualizing="False"
VirtualizingStackPanel.VirtualizationMode="Standard"
GotFocus="TreeView1_GotFocus"
SelectedItemChanged="{Binding ElementName=dirTree, Path=SelectedItem}"/>
</ScrollViewer>
</Border>
</Grid>
</Popup>