У меня есть древовидное представление, привязанное к рекурсивному классу, и я хотел бы позволить пользователю добавлять элемент с помощью кнопки, когда он пролетает над узлом (например, OneNote:
)
Я пытался с этим кодом в файле xaml:
<TreeView Grid.Row="1"
BorderBrush="{x:Null}"
ItemsSource="{Binding Law.RootGroup.Groups}">
<i:Interaction.Behaviors>
<functions:BindableSelectedItemBehavior SelectedItem="{Binding SelectedGroup, Mode=TwoWay}" />
</i:Interaction.Behaviors>
<TreeView.ItemTemplate>
<HierarchicalDataTemplate DataType="{x:Type law:BimFluxGroup}"
ItemsSource="{Binding Groups}">
<Grid Margin="0,0,2,0" Background="Transparent">
<Grid.RowDefinitions>
<RowDefinition SharedSizeGroup="LawRowHeight"/>
</Grid.RowDefinitions>
<TextBlock Text="{Binding Name}" VerticalAlignment="Center">
<i:Interaction.Triggers>
<i:EventTrigger EventName="MouseEnter">
<i:InvokeCommandAction
Command="{Binding ShowPopUpCommand,
RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}}">
<i:InvokeCommandAction.CommandParameter>
<MultiBinding Converter="{StaticResource MultiConverter}">
<Binding RelativeSource="{RelativeSource AncestorType={x:Type TextBlock}}" />
<Binding />
</MultiBinding>
</i:InvokeCommandAction.CommandParameter>
</i:InvokeCommandAction>
</i:EventTrigger>
<i:EventTrigger EventName="MouseLeave">
<i:InvokeCommandAction
Command="{Binding CloseToolTipCommand,
RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
</TextBlock>
</Grid>
</HierarchicalDataTemplate>
</TreeView.ItemTemplate>
</TreeView>
и с этим в файле cs:
private ICommand _showPopUpCommand;
public ICommand ShowPopUpCommand
{
get
{
return _showPopUpCommand ?? (_showPopUpCommand = new RelayCommand<object>(obj =>
{
if (!(obj is object[] values)) return;
if (!(Resources["AddGroup"] is Popup)) return;
if (!(values[1] is BimFluxGroup group)) return;
_popup = (Popup)Resources["AddGroup"];
_popup.DataContext = group;
_popup.PlacementTarget = values[0] as UIElement; ;
_popup.StaysOpen = false;
_popup.IsOpen = true;
}));
}
}
Но с этим кодом мое всплывающее окно постоянно мигает.