どんな助けでも大歓迎です。私はWPFを初めて使用します。xmlファイルによって入力されているツリービューがあります。ツリービューアイテムを選択すると、テキストボックスに表示される必要があります。ポップアップ内にツリービューがあり、問題のテキストボックスを選択すると、ツリービューでポップアップが表示され、ユーザーにツリービューでの選択を促すことができます。その後、そのツリービューの選択を同じテキストボックスに戻す必要があります。これが私のコードです:
<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>