Click here to Skip to main content
15,867,453 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am using UWP and find out that the GotFocus and LosFocus either do not work at all for Rectangle.


<Rectangle VerticalAlignment="Top"  Margin="10" Width="100" Height="100" x:Name="FocusRect"
                      Fill="Red" LostFocus="FocusRect_LostFocus" GotFocus="FocusRect_GotFocus"/>


private void FocusRect_LostFocus(object sender, RoutedEventArgs e)
{
var rect = sender as Windows.UI.Xaml.Shapes.Rectangle;
rect.Fill = new SolidColorBrush(Colors.Yellow);
}

private void FocusRect_GotFocus(object sender, RoutedEventArgs e)
{
var rect = sender as Windows.UI.Xaml.Shapes.Rectangle;
rect.Fill = new SolidColorBrush(Colors.Blue);
}

What I have tried:

tested Button and Rectangle component in UWP windows 10 based on visual studio 2017.
Posted
Updated 21-May-17 9:33am
v4
Comments
[no name] 21-May-17 17:47pm    
Rectangles aren't controls that can get focus. Try mouseenter and mouseleave
Seraph_summer 22-May-17 15:12pm    
I can not find mouseenter and mouseleave event.
instead GotFocus and LostFocus events are availabel, however, they do not work.
[no name] 22-May-17 20:58pm    
If you couldn't find the mouseenter or mouseleave events, either you didn't look very hard or you didn't look at all.
Seraph_summer 23-May-17 15:26pm    
thank you for your help first of all, however, I really can not find it, just have a look at the MSDN webpage for UWP rectangel:
https://docs.microsoft.com/en-us/uwp/api/windows.ui.xaml.shapes.rectangle
I think this page should cover all the events for rectangle, can you find any mouse events?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900