WPF Frames - open links in external browser - html

I have a Frame (used to display a local html file) in a WPF window. I would like that when the user clicks on a link or such, this is opened in an external browser window ( user's default web browser).
Any ideas how to go about this please?

Just do it:
private void Frame_Navigating(object sender, NavigatingCancelEventArgs e)
{
// You should make sure the links are different.
if (IsExternalLink(e.Uri))
{
// open links in extbrowser.
Process.Start(e.Uri.AbsoluteUri);
// cancel the event, and Frame cannot perform navigation operation.
e.Cancel = true;
}
}
Another solution:
ExternalLinks use the Click event instead of the RequestNavigate event.

<TextBlock>
<Hyperlink NavigateUri="http://www.google.com" TargetName="_top">
Go Google!
</Hyperlink>
</TextBlock>

This is a really informative article Launching the Browser from a Hyperlink and goes some to explaining what you need, read through the bullet points of "Browser (XBAP or Loose XAML)".
Setting the TargetName="_self" will open the link in the current frame, which I gather is what you want.

Related

xamarin: How to handle image click on google maps infowindow click in android

I have created a CustomMapRenderer on my Droid project to deal with the map custom rending and display of custom Pin and Info Window. This is all working fine and in my function
public Android.Views.View GetInfoContents(Marker marker)
I can show the info text using the MapInfoWindow.axml
However I have an issue that on the form I have a Button and I want to be able to hook in to the on click event on that ImageView but I notice that click event is only available on the complete InfoWindow and there is no way to specifically track the click on the individual item on that window.
I tried to use the following code to check:
callImage.Click += (s, e) =>
{
Xamarin.Essentials.PhoneDialer.Open(PinCustom.MobileNo);
};
the call always reaches
NativeMap.InfoWindowClick += OnInfoWindowClick;
can someone please help in hooking on to the individual item click instead of working with the complete InfoWindow?
it seems could not respond the click event of ImageView.
An info window is not a live View. Instead, Android will convert the
View to a static bitmap and display that as an image. This means that
while an info window can respond to a click event, it cannot respond
to any touch events or gestures, and the individual controls in the
info window cannot respond to their own click events.
you could refer to Custom the Info Window

MediaCapture and Window VisibilityChanged

[Question]
On Windows Phone 8.1, what exactly happens in between the time when the user leaves the app and the OnSuspended event fires? I'm having trouble with the ability to manage objects in that span, in particular MediaCpture object.
To better explain the problem, here is the scenario:
The user is on a page with a video preview being pumped to a CaptureElement
The user taps the Start button
The user taps Back button and returns to the page with a broken MediaCapture
With WinRT there isn't an ObscuredEvent and OnNavigatingFrom doesn’t fire unless you’re going to another page in the same Frame. After some investigation, I've found that the only event that fires is Window.Current.VisibilityChanged
I've gone ahead and hook it when the page is NavigatedTo and unhooked in OnNavigatedFrom (see ex2 below). Inside the event, I check for parameter that tells if the app is hiding or showing and dispose/initialize accordingly(see ex.1 below).
[Problem]
However, this only works with the debugger attached. If I do this without the debugger attached, it doesn't reinitialize and frequently crashes the camera and I have to literally reboot the device.
Code Example 1 (note: e.Visible == false is leaving the app and true when returning)
async void Current_VisibilityChanged(object sender, VisibilityChangedEventArgs e)
{
if (!e.Visible) //means leaving the app
{
await DisposeAll(); //cleans the MediaCapture and CaptureElement
}
else
{
if(mediaCaptureManager != null) await DisposeAll();
await Initialization(); //set up camera again
}
}
Example 2 (hooking into the event)
protected override void OnNavigatedTo(NavigationEventArgs e)
{
Window.Current.VisibilityChanged += Current_VisibilityChanged;
this.navigationHelper.OnNavigatedTo(e);
}
protected async override void OnNavigatedFrom(NavigationEventArgs e)
{
Window.Current.VisibilityChanged -= Current_VisibilityChanged;
this.navigationHelper.OnNavigatedFrom(e);
}
[Update: Resolution]
Instead of using VisibilityChanged, hook into Window.Current.Activated on the page's constructor. With the debugger completely detached, the Activated event will provide the WindowActivationState parameter in the WindowActivatedEventArgs. Like this:
private async void CurrentOnActivated(object sender, WindowActivatedEventArgs e)
{
if(e.WindowActivationState == CoreWindowActivationState.Deactivated)
{
//dispose MediaCapture here
}
else if(e.WindowActivationState == CoreWindowActivationState.CodeActivated || e.WindowActivationState == CoreWindowActivationState.PointerActivated)
{
//initialize MediaCapture here
}
}
See my answer in https://stackoverflow.com/a/28592882/3998132. Using Window.VisibilityChanged in conjunction with your Page\UserControl Loaded\Unloaded handler should solve your issue I believe.
Using Window.Activated is less desirable than Window.VisibilityChanged because Activated relates to being visible AND having focus where as VisibilityChanged only pertains to visibility. For showing a preview having focus is not applicable. Since Windows Store apps on Windows Phone can only have one Window showing there is no difference in using either however if your app becomes universal and runs on let's say on Windows 8+ Modern shell (which can show multiple Store apps with the Snap window feature) or Windows 10 desktop (which can support multiple Store apps showing at the same time) you will not want to stop preview when a user changes focus from your app but your app is still showing.
I'm not sure if it wouldn't be more suitable to use Suspending/Resuming events. Note only that in this case, you will have to debug it properly - it behaves little different while being run with/without debugger attached.
As for the code - hooking your event in OnNavigatedTo/OnNavigatedFrom is not a good idea - when the OS suspends the app and you are using SuspensionManager then OnNavigatedFrom will be called, but when you go back to your app (resume it), then OnNavigatedTo will not be called.
Using Window events may also work here, but why not subscribe it once, somewhere in constructor? - it's window-wide and hence in phone there is only one window, which stands for app, then subscribe once. In this case, you may add a line that recognizes the current page in window and if that page contains mediacapture then dispose (create similar). Then you can also dispose/initialize in navigation events in case user doesn't leave your app and just navigate.

Windows Store app button respond to click but event is not fired successfully

I go this response in Certification report:
The app does not appear to fully support touch input. The various
tiles on the main screen respond to touch/clicks but do not launch an
action. Touch support in this app do not appear to work to our
reviewers. Please see:
http://msdn.microsoft.com/en-us/library/windows/apps/Hh761498.aspx for
some of the common interactions for keyboard, mouse and touch.
This has never been an issue while developing and testing on several desktop computers and Surface RT. Any ideas on what might be the cause, or how I might reproduce it? The actions mentioned are hooked up to event handlers in code behind and use the navigation model with view models as parameters. I can post an example if needed, but there is nothing special in that code. What could cause a event-bound button to appear to be pressed but not call the handler, on some environments?
Extracts from one of the main features that the testers mention as non-functional:
View:
<GridView ItemsSource="{Binding Source={StaticResource groupedItemsViewSource}}"
ItemClick="ItemView_ItemClick"..
Code behind:
void ItemView_ItemClick(object sender, ItemClickEventArgs e)
{
var foodItem = (FoodItemViewModel)e.ClickedItem;
var mainViewModel = (MainViewModel)this.DefaultViewModel["MainViewModel"];
mainViewModel.CurrentItem = foodItem;
this.Frame.Navigate(typeof(ItemDetailPageReadOnly), (MainViewModel)mainViewModel);
}
From ItemDetailPageReadOnly:
protected override void LoadState(Object navigationParameter,
Dictionary pageState)
{
if (pageState != null && pageState.ContainsKey("SelectedItem"))
{
navigationParameter = pageState["SelectedItem"];
}
var mainVm = (MainViewModel)navigationParameter;
this.DefaultViewModel["MainViewModel"] = mainVm;
this.DefaultViewModel["Item"] = mainVm.CurrentItem;
}
I would expect a NullPointerException if any of the parameters were null, not the described behavior from the testers.
you should use one of the higher level events unless you need to respond to a specific portion of the gesture. http://msdn.microsoft.com/en-us/library/windows/apps/xaml/hh994936.aspx

Setting the application focus to a java-program in Ubuntu/LTSP

We are using LTSP with Thin-Clients. We are using it, to run a Java-Swing-Application. The users should not be able to do anything else, so instead of a Gnome-Session we use a shell-script to start our application.
Nearly everything works perfect but one thing: When the Thin-Client starts, the application starts too but doesn't receive the focus. We have to click once with the mouse inside the application, which is not that good, because the application is designed to be used without a mouse.
I didn't found anything useful, a toFront() on my Main Frame wasn't successful.
Has anyone any better suggestions??
You can use method java.awt.Window#setAlwaysOnTop(boolean) to grab the focus and after the first user interaction reset the alwayOnTop property.
You could try to call requestFocus on your JFrame as soon as it becomes visible:
JFrame frame = new JFrame();
frame.addComponentListener(new ComponentAdapter() {
public void componentShown(ComponentEvent e) {
((JFrame) e.getSource()).requestFocus();
}
});
frame.setVisible(true);

making a swf a clickable link with the pointer icon

I have a swf embedded into a site, and I want the swf to be clickable so when you click on it it goes to another page. I tried wrapping the whole flash object in tags, and that makes it clickable but the biggest problem I'm having is when you roll over it with the mouse the pointer icon doesn't come up, it just looks like the regular arrow. I tried playing with the css and doing cursor:pointer, but it still doesn't work. Any suggestions? I can edit the .fla file and add some actionscript 2.0 to it, but I'm not sure what to add or where. I'd rather do it through html or css, but if I have to do it in flash that's ok too.
Also, I have an invisible button over the whole thing called, MYbtn
i think that the best solution is to add some code in your fla. Open it with Flash and locate the timeline. Right-click on the first frame, "Actions" and you can enter your code.
You can divide your problem in two point:
Display a link cursor when the mouse
is over
Move your browser to your
url when the user press the mouse
button
For the first problem this code should do the work:
this.buttonMode = true;
For the second problem:
import flash.events.MouseEvent;
import flash.external.ExternalInterface;
this.addEventListener(MouseEvent.CLICK, function(evt:MouseEvent):void{
ExternalInterface.call("window.location.href = 'http://www.google.com'");
});
I haven't checked with Flash but this should work
If you have access to the .fla file, why don't you just edit it so that clicking anywhere on the screen redirects you to a new page? You can create an invisible button or something and use some actionscript to make it move people to a new page. I'm not exactly sure how you do it, but I've definitely made links in SWF files before and it's definitely possible.
The cursor should come up on most browsers , although I still haven't managed to get it to work on Chrome for Mac.
this.mouseEnabled = true;
this.buttonMode = true;
addEventListener(MouseEvent.CLICK , mouseClickHandler );
function mouseClickHandler(event:MouseEvent):void
{
navigateToURL( new URLRequest("your location"));
}
Check the docs for more info on navigateToURL
http://www.adobe.com/livedocs/flex/2/langref/flash/net/package.html