Reputation: 5478
I have a requirement, where on a window my button control is invisible, but when the user accidently hovers his mouse on that area the button gets visible. Kind of like an Easter Egg. Below is my code for the XAML but it doesn't seem to work.
<Button Margin="0,0,20,0" Grid.Row="3" HorizontalAlignment="Right"
Name="CopyText" Width="75" Height="25">
<Button.Style>
<Style TargetType="{x:Type Button}">
<Setter Property="Visibility" Value="Hidden" />
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Visibility" Value="Visible" />
</Trigger>
</Style.Triggers>
</Style>
</Button.Style>
</Button>
Upvotes: 0
Views: 4591
Reputation: 19294
Define a ControlTemplate
with a border having transparent background + invisible button within. Then on mouse over border you can set visibility of button to Visible.
MSDN says some interestin things about visibility : Elements where Visibility is not Visible do not participate in input events (or commands), do not influence either the Measure or Arrange passes of layout, are not in a tab sequence, and will not be reported in hit testing.
That explains the behaviour you noticed.
Then in case you write a ControlTemplate
, the button not hidding again after click
might be because it has focus : it would make some sense that a focused element can't
be set invisible. I'd try make it loose focus in click handler (focus on smthg else).
Upvotes: 1