How to handle ManipulationCompleted event in windows phone 8? - c#

I have the following code but it is not working can anyone suggest me what changes i need to do in order to making it working .
Mainscroll.ManipulationCompleted += new EventHandler<System.Windows.Input.ManipulationCompletedEventArgs>(Mainscroll_completed);
private void Mainscroll_completed(object sender, System.Windows.Input.ManipulationCompletedEventArgs e)
{
UIElement target = sender as UIElement;
target.AddHandler(UIElement.ManipulationCompletedEvent, new EventHandler(layoutroot), true);
// throw new NotImplementedException();
}
private void layoutroot(object sender, EventArgs e)
{
MessageBox.Show("done");
}

Replace this line:
Mainscroll.ManipulationCompleted +=
new EventHandler<System.Windows.Input.ManipulationCompletedEventArgs>(Mainscroll_completed);
with this line:
this.Mainscroll.AddHandler(
Pivot.ManipulationCompletedEvent,
new EventHandler<ManipulationCompletedEventArgs>(Mainscroll_completed), true);
and remove:
target.AddHandler(UIElement.ManipulationCompletedEvent......

Related

WPF custom context menu click event not firing

I'm creating a custom context menu using a WebBrowser inside a WindowsFormsHost. But for some reason, the click event I assign to the menu item is not firing. Other events I assign are.
private void Window_Loaded(object sender, RoutedEventArgs e)
{
System.Windows.Forms.WebBrowser browser = new System.Windows.Forms.WebBrowser();
browser.IsWebBrowserContextMenuEnabled = false;
System.Windows.Forms.ContextMenu contextMenu = new System.Windows.Forms.ContextMenu();
System.Windows.Forms.MenuItem menuItem = new System.Windows.Forms.MenuItem()
{
Text = "Add comment"
};
// not firing
menuItem.Click += new EventHandler(menuItem_Click);
// is firing
menuItem.Select += new System.EventHandler(menuItem_Click);
contextMenu.MenuItems.Add(menuItem);
browser.ContextMenu = contextMenu;
// is firing
browser.DocumentCompleted += new System.Windows.Forms.WebBrowserDocumentCompletedEventHandler(browser_DocumentCompleted);
// is firing
browser.HandleCreated += new System.EventHandler(browser_HandleCreated);
windowsFormsHost.Child = browser;
browser.DocumentText = "Test";
}
void browser_HandleCreated(object sender, EventArgs e)
{
throw new NotImplementedException();
}
void browser_DocumentCompleted(object sender, System.Windows.Forms.WebBrowserDocumentCompletedEventArgs e)
{
throw new NotImplementedException();
}
void menuItem_Click(object sender, EventArgs e)
{
throw new NotImplementedException();
}
What am I missing?
I know this question is old, but I just ran into the same problem. I fixed it by using a ContextMenuStrip instead of a ContextMenu.
System.Windows.Forms.ContextMenuStrip webBrowserMenu = new System.Windows.Forms.ContextMenuStrip();
System.Windows.Forms.ToolStripMenuItem refreshItem = new System.Windows.Forms.ToolStripMenuItem("Refresh");
refreshItem.Click += new System.EventHandler(refreshMenuItem_Click);
webBrowserMenu.Items.Add(refreshItem);
webBrowser1.ContextMenuStrip = webBrowserMenu;

cannot invoke properties of control

I'm trying to programmatically create a axWindowsMediaPlayer and show it:
private void button1_Click(object sender, EventArgs e)
{
AxWMPLib.AxWindowsMediaPlayer wmplayer = new AxWMPLib.AxWindowsMediaPlayer();
wmplayer.Size = new Size(200, 200);
wmplayer.enableContextMenu = false; //here it throws an exception
this.Controls.Add(wmplayer);
}
but it says {Property set of 'enableContextMenu' cannot be invoked at this time.}
why is that? why can I set Size but not enableContextMenu?
I found the solution:
It is important that you do changes and/or function calls after you added wmplayer to this.Controls.
I don't know why wmplayer.Size worked, but it is definitively the exception..
private void button1_Click(object sender, EventArgs e)
{
AxWMPLib.AxWindowsMediaPlayer wmplayer = new AxWMPLib.AxWindowsMediaPlayer();
this.Controls.Add(wmplayer);
wmplayer.Size = new Size(200, 200);
wmplayer.enableContextMenu = false; //here it throws an exception
}
works perfectly fine..

Clear listbox when new tab selected

I am trying to clear the contents of a listbox when a new tab is seleced. Here is what I got, but nothing happens.
private void tabControl1_SelectedIndexChanged(object sender, EventArgs e)
{
if (tabControl1.SelectedTab == tabControl1.TabPages["entryTab"])
{
readBox.Items.Clear();
reminderBox.Items.Clear();
}
}
Try something like this in your form load
tabControl1.Selecting += new TabControlCancelEventHandler(tabControl1_SelectedIndexChanged);
// Try this set null to DataSource
private void tabControl1_SelectedIndexChanged(object sender, EventArgs e)
{
if (tabControl1.SelectedTab == tabControl1.TabPages["entryTab"])
{
readBox.DataSource = null;
reminderBox.DataSource = null;
}
}

why am i getting .UnauthorizedAccessException?

I am trying to retrieve images from media library to a warp panel inside listbox 'lstImageFromMediaLibrary', also am trying that while the images load i show a loading screen using a usercontrol and adding it to popup.child
but i am getting this exceeption 'UnauthorizedAccessException'
when i remove all backgrougWorker related code no such unauthorized access is there....
void backroungWorker_DoWork(object sender, DoWorkEventArgs e)
{
foreach (Picture p in mediaLibrary.Pictures)
{
bitmapImage.SetSource(p.GetThumbnail());
lstBitmapImage.Add(bitmapImage);
}
this.lstImageFromMediaLibrary.ItemsSource = lstBitmapImage;
}
any help is appriciated , i hope i made myself clear....
EDIT:
ok so now m doing this
BackgroundWorker backroungWorker = new BackgroundWorker();
Popup popup = new Popup();
public PanoramaPage1()
{
InitializeComponent();
showpopup();
init();
}
private void init()
{
backroungWorker.WorkerReportsProgress = true;
backroungWorker.DoWork += new DoWorkEventHandler(backroungWorker_DoWork);
backroungWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(backroungWorker_RunWorkerCompleted);
backroungWorker.ProgressChanged+=new ProgressChangedEventHandler(backroungWorker_ProgressChanged);
backroungWorker.RunWorkerAsync();
}
void backroungWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
this.Dispatcher.BeginInvoke(() =>
{
popup.IsOpen = false;
}
);
}
void backroungWorker_DoWork(object sender, DoWorkEventArgs e)
{
backroungWorker.ReportProgress(10);
}
void backroungWorker_ProgressChanged(object sender, ProgressChangedEventArgs e)
{
this.InitializePage();
}
private void showpopup()
{
popup.Child = new SplashScreenControl();
popup.Width = 480;
popup.IsOpen = true;
}
private void InitializePage()
{
MediaLibrary mediaLibrary = new MediaLibrary();
List<BitmapImage> lstBitmapImage = new List<BitmapImage>();
foreach (Picture p in mediaLibrary.Pictures)
{
BitmapImage bitmapImage = new BitmapImage();
bitmapImage.SetSource(p.GetThumbnail());
lstBitmapImage.Add(bitmapImage);
}
this.lstImageFromMediaLibrary.ItemsSource = lstBitmapImage;
}
but still the progress bar just shows a dot and nothing else.....
You are accessing your User Interface in your DoWork Event. You should be communicating to your application through the Background Worker Events such as the ProgressChanged or the RunWorkerCompleted Events.
From First link:
You must be careful not to manipulate any user-interface objects in your DoWork event handler. Instead, communicate to the user interface through the BackgroundWorker events.

C# - WP7 WebBrowser Navigating Event Handler

I cannot figure out how to catch the Navigating event on the WebBrowser control. Basically I'm trying to figure out how trigger the progress bar to show when a user clicks a link on a page.
Here is the code I use to show the progress bar and then hide it on page loaded. Can someone help me out with the event handler for Navigating?
private void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e)
{
progressBar.IsIndeterminate = true;
progressBar.Visibility = Visibility.Visible;
webBrowser.Navigate(new Uri(MY_URL, UriKind.Absolute));
webBrowser.LoadCompleted += new System.Windows.Navigation.LoadCompletedEventHandler(PageLoadCompleted);
webBrowser.Navigating = ?
}
private void PageLoadCompleted(object sender, System.Windows.Navigation.NavigationEventArgs e)
{
progressBar.IsIndeterminate = false;
progressBar.Visibility = Visibility.Collapsed;
}
The documentation you seek is here. You can write
webBrowser.Navigating += webBrowser_Navigating;
// ...
void webBrowser_Navigating( object sender, NavigatingEventArgs e )
{
// ...
}
The answer of by VisualStuart helped me solve my problem.
My now working code is as below :
private void MyButton1_Click(object sender, RoutedEventArgs e)
{
MyprogressBar.IsIndeterminate = true;
MyprogressBar.Visibility = Visibility.Visible;
string site = MyTextBox1.Text;
webBrowser1.Navigate(new Uri(site, UriKind.Absolute));
webBrowser1.Navigating += webBrowser1_Navigating;
webBrowser1.LoadCompleted += new System.Windows.Navigation.LoadCompletedEventHandler(webBrowser1_LoadCompleted);
}
private void webBrowser1_Navigating(object sender, NavigatingEventArgs e)
{
MyTextBox1.Text = e.Uri.ToString();
MyprogressBar.IsIndeterminate = true;
MyprogressBar.Visibility = Visibility.Visible;
}

Categories

Resources