我有一个包含许多项目的清单箱。 当我对某个项目置之不理时,我需要表现出相当强烈的愤怒。 我确信,每个项目的填满是浪费资源,因此,我只想在项目一上对项目一作改动,修改项目内的内容目录,以包括“动.”。 这是我迄今为止所做的事:(简化版)(该法典可留到卡西姆尔)。
<Page
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Page.Resources>
<ControlTemplate x:Key="WithPopup" TargetType="ContentControl">
<Grid>
<ContentPresenter Content="{TemplateBinding Content}" Name="Target" />
<Popup PlacementTarget="{Binding ElementName=Target}" IsOpen="True" >
<Border BorderBrush="Red" BorderThickness="1" Background="Pink">
<TextBlock Text="I d like this to behave like a Popup - not a tooltip!" Margin="10" />
</Border>
</Popup>
</Grid>
</ControlTemplate>
</Page.Resources>
<Grid Height="20" Margin="50,50,0,0" Name="ParentGrid">
<ContentControl>
<TextBlock x:Name="TargetControl" Text="Hover over me!" />
<ContentControl.Style>
<Style TargetType="ContentControl">
<Style.Triggers>
<DataTrigger Binding="{Binding IsMouseOver, ElementName=TargetControl}" Value="True">
<Setter Property="Template" Value="{StaticResource WithPopup}" />
</DataTrigger>
</Style.Triggers>
</Style>
</ContentControl.Style>
</ContentControl>
</Grid>
</Page>
The problem is that when I try to MouseOver the Popup - it disappears (like a tooltip) because I I m the mouse is leaving the original ControlTemplate - which causes the template with the Popup to disappear. Any ideas? Edit: I have codebehind available as well to achieve this (even though I d prefer xaml)