UWP mediaelement fullscreen window object not receiving event handlers - win-universal-app

Here is the code which I am using to simply toggle fullscreen in UWP media element:
private void SingleMediaElement_DoubleTapped(object sender, DoubleTappedRoutedEventArgs e)
{
SingleMediaElement.IsFullWindow = !SingleMediaElement.IsFullWindow;
}
I can make it fullscreen by double clicking, but I am not able to exit fullscreen, because apparently fullscreen mode is a different object. How do I receive that object and manage the same event handler on it?

Try ApplicationView instead:
private void SingleMediaElement_DoubleTapped(object sender, DoubleTappedRoutedEventArgs e)
{
var view = ApplicationView.GetForCurrentView();
if (view.IsFullScreenMode)
view.ExitFullScreenMode();
else
view.TryEnterFullScreenMode();
}

This problem was solved by using Media element Transport controls double tapped event instead of Media Element double tapped event.

Related

Can you override the Navigation Controllers 'InteractivePopGestureRecognizer' action?

I'm searching for ways to implement a swipe gesture recognizer which only triggers when you swipe from the outer left side of the screen to the right. We need the gesture to open our custom SideMenu. I tried to use a simple UISwipeGestureRecognizer with the SwipeDirection property set to right, but that gets triggered on every swipe from left to right, no matter what the startpoint of the swipe is.
Ideally, we want the animation of it to look and feel like the InteractivePopGestureRecognizer of a UINavigationController. We are already using a NavigationController, which pushed our MainView over our IntroView. Now, we disable the InteractivePopGestureRecognizer, so you aren't able to go back to the IntroView. That's our problem. If it is possible, we don't want to disable the gesture of the NavigationController, but change the action of it. So the swipe from the far left side of the screen to the right would not pop the current viewcontroller, but open our SideMenu.
Is it possible to override the InteractivePopGestureRecognizer to change the action of it? If this isn't possible, do you have another idea on how to create the exact same gesture recognizer? It has to be possible somehow because many apps only open their SideMenu if your startpoint of the gesture is the left (or right) side of the screen. (e.g. Reddit)
Thanks for any help in advance.
You could use Touch Events and UISwipeGestureRecognizer to do that.
The workaround that is override TouchesBegan method to detect the started point whether fit your needs, and if so add UISwipeGestureRecognizer for View.
SwipeGestureRecognizer rightSwipeGesture;
public override void TouchesBegan (NSSet touches, UIEvent evt)
{
base.TouchesBegan (touches, evt);
UITouch touch = touches.AnyObject as UITouch;
if (touch != null)
{
//code here to handle touch
CoreGraphics.CGPoint swipPoint = touch.LocationInView(View);
if(swipPoint.X < 0.5)
{
rightSwipeGesture = new SwipeGestureRecognizer { Direction = SwipeDirection.Right };
rightSwipeGesture.Swiped += OnSwiped;
View.AddGestureRecognizers(rightSwipeGesture);
}
}
}
public override void TouchesEnded (NSSet touches, UIEvent evt)
{
base.TouchesBegan (touches, evt);
if(null != rightSwipeGesture ){
rightSwipeGesture.Swiped -= OnSwiped;
View.RemoveGestureRecognizers(rightSwipeGesture);
}
}
=============================Update=================================
I found a workaround only use one GestureRecognizer will make it works. You could have a look at UIScreenEdgePanGestureRecognizer. Although it's a Pan gesture, however if you not deal with somethind with the added view, it will work as a swip gesture. In addition, UIScreenEdgePanGestureRecognizer only can work when on the screen edge. You could set the Left edge to handle your needs.
For example:
UIScreenEdgePanGestureRecognizer panRightGestureRecognizer = new UIScreenEdgePanGestureRecognizer();
panRightGestureRecognizer.Edges = UIRectEdge.Left;
panRightGestureRecognizer.AddTarget(() => HandleSwap(panRightGestureRecognizer));
View.AddGestureRecognizer(panRightGestureRecognizer);
private void HandleSwip(UIScreenEdgePanGestureRecognizer panRightGestureRecognizer)
{
Point point = (Point)panRightGestureRecognizer.TranslationInView(View);
if (panRightGestureRecognizer.State == UGestureRecognizerState.Began)
{
Console.WriteLine("Show slider view");
}
}

close a ContentDialog after LostFocus on it and click on the MainPage Interface

I have used a ContentDialog to create a PopUp ContentDialog like the one in the Groove App:
the problem is that,I can't close it when I click on any part of the MainPage Interface and loose focus,I have tried like this,but it doesn't work :(,it closes only after I send data from the ContentDialog
MainPage.xaml:
private void MenuButton_Click(object sender, RoutedEventArgs e)
{
AddFavoris formTask = new AddFavoris();
t = formTask.ShowAsync();
string f = formTask.Opgave;
formTask.LostFocus += new RoutedEventHandler(formTask_LostFocus);
}
private void formTask_LostFocus(object sender, RoutedEventArgs e)
{
t.Cancel();
}
so,is there any solutions can I use to have a ContrentDialog that will be closed after a Click on the MainPage interface and lost focus on it
thanks for help
Use Flyout instead of using a ContentDialog. Flyouts can be dismissed by tapping or clicking somewhere outside the flyout.
For more information: Guidelines for flyouts, Guidelines for dialog controls

How to implement double click to a button in C#

how to implement double click event for a button in C# window application
strong text
Add an event handler
btn.doubleClick += btn_doubleClick;
Then, define
private void btn_doubleClick ( object sender, EventArgs e )
{
// do stuff
}

How to close user control used in radgrid filtering?

I have a radgrid, for date column i have created a custom user control for filtering. I need to create a close button to close the user control. There are no close events which i can call. I don't want to make visibility collapsed. I started with something below:
public partial class DateFilterControl : UserControl, IFilteringControl
{
public event CloseEventHandler Close;
public delegate void CloseEventHandler();
private void Button_Click(object sender, RoutedEventArgs e)
{
this.Close();
}
}
It is throwing nullreference exception which is obvious to come. What code do i need to put to close the user control?
use Messaging Service. With this you can close the window in ViewModel so no need to give close function in Backend. Add Command property to Cancel button
<Button Content="Cancel" Command="{Binding CancelCommand}"/>
Now in the ViewModel add the RelayCommand property in that add
Messenger.Default.Send<bool>(true, typeof(XViewModel));
Now in the BackEnd of this userControl adds following in the constructor.
Messenger.Default.Register<bool>(this, typeof(ScheduleViewModel), (b) =>
{
if (b == true)
{
this.DialogResult = true;
}
});
Now u can close the Window...
This will surely helps u...

Fire parent click event when child is clicked in windows form user control

I have a user control
public partial class ButtonControl : UserControl
which has two controls of label and picturebox
this.pictureBox1 = new System.Windows.Forms.PictureBox();
this.text = new System.Windows.Forms.Label();
I have used this control in a windows form
this.appointmentButton = new DentalSoft.UI.Controls.ButtonControl();
created an event
this.appointmentButton.Click += new System.EventHandler(this.appointmentButton_Click);
but the problem is, if i click on the image or the label inside of the control, the click event doesn't fire.
I want to fire this click event no matter where the user clicks inside of the control. Is it possible?
Yes it is a simple matter. When you click on the child controls they receive the click event and the user control does not. So you can subscribe to the child control click events and when they occur simply raise the usercontrol click event and it will appear to click no matter where the mouse is positioned.
Just double click on the picturebox and the label to create the click event handlers then add a line of code to call the parent usercontrol OnClick method.
private void text_Click(object sender, EventArgs e)
{
this.OnClick(new EventArgs());
}
private void pictureBox1_Click(object sender, EventArgs e)
{
this.OnClick(new EventArgs());
}
I solved this problem the following way. I wanted to changes the background images of the parent PictureBox when the child Label was clicked. I played around some and found I could call the event handler in the following way.
private void Label_Click(object sender, EventArgs e)
{
Label label = (Label)sender;
Box_Click(label.Parent, e);
}
private void Box_Click(object sender, EventArgs e)
{
//
PictureBox box = sender as PictureBox;
//
if (isMine[int.Parse(box.Name)])
{
box.Image = Image.FromFile(#"..\..\images\BoxRedX.jpg");
MessageBox.Show("Game Over");
}
else
{
box.Image = Image.FromFile(#"..\..\images\BoxGray.jpg");
}
}
As you can see I grab the Child and using it to reference its parent and send it to the parents click event. This is the code I used to work in my project. The important method is the first on listed. The second is there for clarity to see how it passed and worked.

Resources