0

我正在编码以在MouseOver打开时弹出一个文本ToggleButton。我也明白了,但真正的问题是弹出的文本不是保持不变,即它在ToggleButton. 另一件事是弹出的文本出现在它ToggleButton本身上,但它应该在它的下方。我怎样才能摆脱这个?

这是我的代码外观

<ToggleButton x:Name="btn" Width="20" Height="15">
    <Image Source="../Images/flag_orange.ico"/>
</ToggleButton>
<Popup x:Name="popUp" IsOpen="{Binding IsChecked, ElementName=btn, Mode=TwoWay}"
       StaysOpen="False" PlacementTarget="{Binding ElementName=btn}"
       Placement="Bottom" PopupAnimation="Slide" HorizontalOffset="-5"
       VerticalOffset="3">
    <Border Background="DarkGray">
        <TextBox Text="Its a place holder for user notes" x:Name="tbText"/>                         
    </Border>                    
</Popup>
<TextBlock x:Name="tbTextBlock" 
           Visibility="{Binding Path=IsMouseOver,ElementName=btn,Mode=OneWay,
                        Converter={StaticResource BoolToVisibilityConverter}}"
           Text="{Binding ElementName=tbText, Path=Text, Mode=TwoWay}" />
4

1 回答 1

0

IsHitTestVisible="False"在您的 TextBlock 上使用。ToggleButton鼠标悬停已被文本块捕获,因此当鼠标悬停出现时,您的鼠标并未悬停TextBlock

要获取 ToggleButton 下方的 TextBlock,请使用 aMargin="0,15,0,0"或 aStackPanel按顺序获取这些控件:

<StackPanel>
  <ToggleButton x:Name="btn" Width="20" Height="15">
    <Image Source="../Images/flag_orange.ico"/>
  </ToggleButton>
  <Popup x:Name="popUp" IsOpen="{Binding IsChecked, ElementName=btn, Mode=TwoWay}"
         StaysOpen="False" PlacementTarget="{Binding ElementName=btn}"
         Placement="Bottom" PopupAnimation="Slide" HorizontalOffset="-5"
         VerticalOffset="3">
    <Border Background="DarkGray">
      <TextBox Text="Its a place holder for user notes" x:Name="tbText"/>
    </Border>
  </Popup>
  <TextBlock x:Name="tbTextBlock" 
         IsHitTestVisible="False"
         Visibility="{Binding Path=IsMouseOver,ElementName=btn,Mode=OneWay,
                      Converter={StaticResource BoolToVisibilityConverter}}"
         Text="{Binding ElementName=tbText, Path=Text, Mode=TwoWay}" />
</StackPanel>
于 2013-11-14T12:03:39.847 回答