Basically, I am using mediaplayerelement, and with CustomMediaTransportControls with some custom buttons, I have one issue need to solve:
The media is set to autoplay, so when source is set, the playing starts, when pause button is clicked, the playing pauses, and the button changes to play state, now when play button is clicked, I want add a function before the playing starts, to first refresh and get a new source then play.
I really don't want to create my own media control if possible, so basically using build in transport control, just some how override playbutton_click, is this doable?
Use PlaybackStateChanged event and check for PlaybackState
public MainPage()
{
this.InitializeComponent();
MediaPlayerElementName.MediaPlayer.PlaybackSession.PlaybackStateChanged += PlaybackSession_PlaybackStateChanged;
}
bool isFirst = true;
private void PlaybackSession_PlaybackStateChanged(MediaPlaybackSession sender, object args)
{
if (sender.PlaybackState == MediaPlaybackState.Playing)
{
if (!isFirst)
{
//Set your New source
isFirst = true;
}
else
isFirst = false;
}
}
Related
I've been trying to intercept the user going back from a page in my Xamarin.Forms UWP app, in order to either block it or present them with an "Are you sure?" dialog.
I've been able to remove the navigation bar back button using this in the constructor of the ContentPage:
NavigationPage.SetHasBackButton(this, false);
However, the back button on the mouse (XButton1) still causes the page to back.
I tried disabling it using this on the page:
protected override bool OnBackButtonPressed()
{
return true;
}
This would disable the hardware back button on something like Android, but it is not called at all when hitting the mouse back button.
I've also tried playing with the PointerPressed event on the UWP MainPage:
public MainPage()
{
this.InitializeComponent();
LoadApplication(new MyApp.App());
this.PointerPressed += MainPage_PointerPressed;
}
private void MainPage_PointerPressed(object sender, PointerRoutedEventArgs e)
{
PointerPoint currentPoint = e.GetCurrentPoint(this);
if (currentPoint.PointerDevice.PointerDeviceType == PointerDeviceType.Mouse)
{
PointerPointProperties pointerProperties = currentPoint.Properties;
if (pointerProperties.IsXButton1Pressed)
{
// back button pressed
}
}
}
This method is called correctly for all mouse inputs except for the XButton1 mouse back button if the app's current page is currently in a NavigationPage - almost like Xamarin.Forms is intercepting it somewhere along the way. Outside of a navigation page it picks up the XButton1 fine, and it always picks up every other input (including XButton2).
Is there a way to intercept or disable the XButton1 back function for a Xamarin.Forms UWP app?
Found a renderer workaround that allows you to handle the back button:
using Xamarin.Forms.Platform.UWP;
using Windows.UI.Xaml.Input;
using Windows.Devices.Input;
[assembly: ExportRenderer(typeof(Xamarin.Forms.Page), typeof(MyApp.UWP.Renderers.PageCustomRenderer))]
namespace MyApp.UWP.Renderers
{
public class PageCustomRenderer : PageRenderer
{
protected override void OnElementChanged(ElementChangedEventArgs<Xamarin.Forms.Page> e)
{
base.OnElementChanged(e);
this.PointerPressed += PageCustomRenderer_PointerPressed;
}
private void PageCustomRenderer_PointerPressed(object sender, PointerRoutedEventArgs e)
{
if (e.Handled) return;
var point = e.GetCurrentPoint(Control);
if (point == null || point.PointerDevice.PointerDeviceType != PointerDeviceType.Mouse) return;
if (point.Properties.IsXButton1Pressed)
{
e.Handled = true;
if (Element != null)
{
Element.SendBackButtonPressed();
}
}
}
}
}
You can then override OnBackButtonPressed on the page as in the OP to stop it (or remove the Element.SendBackButtonPressed() from the renderer above to disable it entirely).
here i have this problem with popup window, i popup an usercontrol in a dll and call this dll in an app, but it shows upon a black page that i have no idear where its from. when i push the '<-' button ,the app directly exit... i can't go back to the app's mainpage where calls it.
I wonder how can I return from the popup window. I tried to hide the popup window, but it doesn't go back to app's mainpage.
public void change_PIN(OnCCB_ChangeUserPINCall changeUserPINCall)
{
Popup ppChangePIN = new Popup();
ChangePIN changePIN = new ChangePIN();
ppChangePIN.Child = changePIN;
ppChangePIN.IsOpen = true;
}
How can I set ppChangePIN.IsOpen=false inside popup window .cs to make it disappear?
Handle back key press event of back button like
step1: first set one flag when popup is open like **bool PopupOpen=True**
step2: When popup is close at that time PopupOpen=False
protected override void OnBackKeyPress(System.ComponentModel.CancelEventArgs e)
{
if(PopupOpen== True)
{
ppChangePIN.IsOpen=false;
PopupOpen=False;
e.Cancel = true;
}
else
{}
}
If any query let me know...
hope it work for you
private bool RemovePopup()
{
if (ppChangePIN == null || !ppChangePIN.IsOpen)
return false;
ppChangePIN.IsOpen = false;
return true;
}
protected override void OnBackKeyPress(CancelEventArgs e)
{
if (RemovePopup())
e.Cancel = true;
}
I have recently created an application for wp7. Now i am ready submit an update for my app. In the i have added a UserControl page(contains a dialog box). I want it to displayed on the MainPage.xaml or in app startup but only for the first app launch. I know how to show a MessageBox for the first time but don't know how to show a xaml page.
if (!IsolatedStorageSettings.ApplicationSettings.Contains("IsFourthLaunchDone"))
{
MessageBox.Show("To Enable Full screen mode, go to settings and select Full Screen Browsing.");
IsolatedStorageSettings.ApplicationSettings["IsFourthLaunchDone"] = true;
}
Can anybody help me with this? Thanks in advance for your help!
Here's an idea of how this is properly done with a MessageBox.
App.xaml.cs:
public static bool IsFourthLaunch = false;
ApplicationLaunching(){
if (!IsolatedStorageSettings.ApplicationSettings.Contains("IsFourthLaunchDone"))
{
IsFourthLaunch = true;
}
}
MainPage.xaml.cs:
MainPage()
{
if (App.isFourthLaunch)
{
Loaded += OnFourthLaunch;
}
}
public void OnFourthLaunch(object sender, RoutedEventArgs e)
{
Loaded -= OnFourthLaunch;
if (App.IsFourthLaunch)
{
MessageBox.Show("To Enable Full screen mode, go to settings and select Full Screen Browsing.");
IsolatedStorageSettings.ApplicationSettings["IsFourthLaunchDone"] = true;
App.IsFourthLaunch = false;
}
}
To do this with a UserControl, add the Control to the page, initially with a Collapsed Visibility. In the scenario you want to display it, change the visibility to Visible. You'll need to figure out in what way you want the Control to work, and probably you'll need to override OnBackKeyPress to provide a logical way for the user to close your control.
protected override void OnBackKeyPress( System.ComponentModel.CancelEventArgs e )
{
if (myControl.Visibility == Visibility.Visible)
{
e.Cancel = true;
myControl.Visibility = Visibility.Collapsed;
}
}
I am building a WinForms Application in C# .NET
The WinForms Application has a ComboBox where the DropDownStyle is set to DropDownList. When the App is launched, I read an XML file to populate the values of the ComboBox. And, at this time, nothing is selected in the ComboBox by default. As a result, buttons Change and Delete are disabled.
Now, when the user selects a value, I want the buttons Change and Delete to be enabled. So far I have accomplished (although, I am not sure that I have done it in the right way).
I have written the code in the SelectionChangeCommitted Event.
private void cbList_SelectionChangeCommitted(object sender, EventArgs e)
{
if (cbList.SelectedItem != null)
{
this.btnModify.Enabled = true;
this.btnRemove.Enabled = true;
}
else
{
this.btnModify.Enabled = false;
this.btnRemove.Enabled = false;
}
}
Now, when I chose a value...the buttons get enabled (as expected). The user then clicks on Delete button and we remove the selected value. Now, there is nothing Selected in the cbList but the buttons are still enabled?
What is the function/event where I check if a value is selected or not and then enable/disable the buttons.
At the moment, dont have Visual Studio, so I dont remember which events we have. But you can make this,
private void CheckButtons()
{
if (cbList.SelectedItem != null)
{
this.btnModify.Enabled = true;
this.btnRemove.Enabled = true;
}
else
{
this.btnModify.Enabled = false;
this.btnRemove.Enabled = false;
}
}
and use your func in event
private void cbList_SelectionChangeCommitted(object sender, EventArgs e)
{
CheckButtons();
}
as you said, after deleting, buttons are still visible, so you can put CheckButtons() function after your delete function like
DeleteX();
CheckButtons();
Ok so I'm trying to move items from one listbox to another by using multiple buttons i.e
I have 2 buttons cmdRight and cmdRight2 which are both disabled on form load
If the user selects a single item on the first listbox a cmdRIght button enables but cmdRight2 is still disabled , if the user selects multiple items on the first listbox a cmdRight2 button enables but cmdRight is disabled.
I've got the move buttons to work but the problem I'm having is after moving multiple items with the cmdRight2 button the cmdRight button enables (which it shouldn't it should only enable after selecting a single item in the listbox). I've tried numerous if statements etc. and yet it still happens.
I'm new to C# so any help would be appreciated.
Thank You
private void lbList1_SelectedIndexChanged(object sender, EventArgs e)
{
if (this.lbList1.SelectedItems != null)
{
cmdRight.Enabled = true; //enable cmdRight
cmdClear.Enabled = true; //enable cmdClear
if (this.lbList1.SelectedItems.Count > 1)//if multiple items selected
{
cmdRight.Enabled = false;
cmdRight2.Enabled = true; //enable cmdRight2
}
}
}
private void cmdRight2_Click(object sender, EventArgs e)
{
foreach (int i in lbList1.SelectedIndices)
{
lbList2.Items.Add(lbList1.Items[i].ToString());
}
while (lbList1.SelectedItems.Count > 0)
{
lbList1.Items.Remove(lbList1.SelectedItems[0]);
}
cmdRight2.Enabled = false;
}
private void cmdRight_Click(object sender, EventArgs e)
{
lbList2.Items.Add(lbList1.SelectedItem); //Add selected item from list1 to list2
lbList1.Items.Remove(lbList1.SelectedItem);//remove the selected item in list1
cmdRight.Enabled = false; //disable cmdRight
}
How about creating one method EnableButtons that enables/disables to buttons according to given criteria like "enable cmdRight2 only if.... is true".
Then, call the method whenever some of the criteria might change. The advantage of this over the way you're doing it now is that the criteria within the method are "absolute" (in that the buttons are either enabled or disabled in one go) instead of "relative" (enable the button when the user does this or that).
You could also call this method from the Application.Idle event instead of calling it in response to some user action.
EDIT
Declare the following method:
private void EnableButtons()
{
controlX.Enabled = (<condition...>);
controlY.Enabled = (<condition...>);
}
You can either invoke that method from the positions in code where something should change in the buttons' enabled states, or you can do the following in the constructor of the form:
public Form1()
{
// Other code...
Application.Idle += new <The respective event handler>;
}
Then, declare a method with the respective signature for the event and call EnableButtons there. This method would be called in situations where your application is "idle" (waiting for user actions).
I think you want
if (this.lbList1.SelectedItems.Count == 1)
{
}
else if(this.lbList1.SelectedItems.Count > 1)
{
}
else
{
}
instead of
if (this.lbList1.SelectedItems != null)
Then you could place all of this in a method called "EnableButtons" as mentioned elsewhere
The problem is that you are removing the items one by one, so when only one item is left, you essentially have one item selected so your program enables the cmdRight. The easiest way around this is to have
cmdRight2.Enabled = false;
cmdRight.Enabled = false;
at the end of the cmdRight2_Click method.