我编码在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}" />
答案 0 :(得分:0)
在TextBlock上使用IsHitTestVisible="False"
。鼠标悬停已被Textblock捕获,因此当ToggleButton
出现时,您的鼠标不会超过TextBlock
。
要在ToggleButton下方获取TextBlock,请使用Margin="0,15,0,0"
或StackPanel
按顺序获取这些控件:
<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>