I need to add a hyperlink button that directs to a webpage to my metro style apps written with C# and XAML. As in Silverlight, there is no NavigateURI option. Is there any other option to make a hyperlink redirect to a specific webpage?
There's a sample in the Sample App Pack that does this.
// Launch a URI.
private async void LaunchUriButton_Click(object sender, RoutedEventArgs e)
{
// Create the URI to launch from a string.
var uri = new Uri(uriToLaunch);
// Launch the URI.
bool success = await Windows.System.Launcher.LaunchUriAsync(uri);
if (success)
{
rootPage.NotifyUser("URI launched: " + uri.AbsoluteUri, NotifyType.StatusMessage);
}
else
{
rootPage.NotifyUser("URI launch failed.", NotifyType.ErrorMessage);
}
}
I don't know about Silverlight but in WPF (almost same as SL) we have TextBlock whose inline tag is Hyperlink.
<TextBlock>
Some text
<Hyperlink
NavigateUri="http://somesite.com"
RequestNavigate="Hyperlink_RequestNavigate">
some site
</Hyperlink>
some more text
</TextBlock>
U said "as in silverlight there is no NavigateURI option in this". No Problem.
i didn't knew about this feature of NavigateURI b4. so what i did was when the user clicked on that link it called the browser to open my requested link. In mouse over i changed cursor to look like hand and text color as red and on mouse leave back to default color (Blue) and cursor (Arrow).
I think u got my point.
I blogged about wiring up HyperlinkButton in Windows8 XAML to launch internet explorer
http://zubairahmed.net/?p=266
Windows.System.Launcher has methods to open the appropriate app for a given Uri or StorageFile. Just wire that up to the click event of your button
Just in case somebody stumbles upon this:
I'm using Visual Studio 2012 RTM on Windows 8 RTM and NavigateURI is back and opens the default metro browser.
Related
Universal app does not allow to remove or disable the close button it seems. We can hide it by going full screen. But when moving cursor over it, brings title bar back. Is there any way to remove the close button?
Reason : I am working on screen time. After allowed time gets over, I want to block the screen. I should remove close button so that user cant get over my app.
Edit : Removing close button wont help completely. It is a part of work. I am just asking how to remove it.
In Windows 10 version 1703 (build 10.0.15063) and beyond, you can prevent the app from closing, using the SystemNavigationManagerPreview class.
Add this to your app manifest:
<Capabilities>
<rescap:Capability Name="confirmAppClose" />
</Capabilities
You need to have the rescap namespace at the Package element:
xmlns:rescap="http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities"
In the constructor of your main form, add:
var sysNavMgr = SystemNavigationManagerPreview.GetForCurrentView();
sysNavMgr.CloseRequested += OnCloseRequested;
OnCloseRequested can be implemented as follows:
private void OnCloseRequested(object sender, SystemNavigationCloseRequestedPreviewEventArgs e)
{
var deferral = e.GetDeferral();
e.Handled = true;
deferral.Complete();
}
With current released API, we are able to customize the color of these three buttons in title bar. But there is no property or method could be used to disable or remove these buttons.
In UWP, we can use ApplicationView.TitleBar | titleBar property to get the title bar like following:
ApplicationViewTitleBar titleBar = Windows.UI.ViewManagement.ApplicationView.GetForCurrentView().TitleBar;
This property's type is ApplicationViewTitleBar. It only has several properties that can customize the button's color like:
titleBar.ButtonBackgroundColor = Windows.UI.Colors.White;
titleBar.ButtonForegroundColor = Windows.UI.Colors.White;
titleBar.ButtonHoverBackgroundColor = Windows.UI.Colors.White;
titleBar.ButtonHoverForegroundColor = Windows.UI.Colors.White;
titleBar.ButtonInactiveBackgroundColor = Windows.UI.Colors.White;
titleBar.ButtonInactiveForegroundColor = Windows.UI.Colors.White;
titleBar.ButtonPressedBackgroundColor = Windows.UI.Colors.White;
titleBar.ButtonPressedForegroundColor = Windows.UI.Colors.White;
Using these properties may make the close button invisible like:
However this won't actually hide these buttons. Users can still minimize or maximize the app and when the pointer is over the top right corner, they will still see the close button.
From Windows 8.1, if we want users to use only an application and do nothing else including closing the application, we can use Kiosk Mode. For more info, please see Enable Kiosk Mode in Windows 8.1 and Set up a kiosk on Windows 10 Pro, Enterprise, or Education. However this won't meet your requirement as you want to block the screen after allowed time gets over.
So UWP may not be the best choice for your requirement. You may try to implement it with classic desktop apps.
in App.Xaml.cs add this code :
// Collapse Title bar
CoreApplication.GetCurrentView().TitleBar.ExtendViewIntoTitleBar = true;
Window.Current.SetTitleBar(null);
ApplicationView view = ApplicationView.GetForCurrentView();
view.TryEnterFullScreenMode();
C++ Version
// COLLAPSE THE TITLE BAR
Windows::ApplicationModel::Core::CoreApplication::GetCurrentView()->TitleBar->ExtendViewIntoTitleBar = true;
Window::Current->SetTitleBar(nullptr);
Windows::UI::ViewManagement::ApplicationView^ view = Windows::UI::ViewManagement::ApplicationView::GetForCurrentView();
view->TryEnterFullScreenMode();
I'm currently working on an Windows Phone App in Visual Studio for my Lumia 1520 with Windows Phone 10.
To navigate between the MainPage and the SecondPage, I use the code:
private void HyperlinkButton_Click(object sender, RoutedEventArgs e){
Frame.Navigate(typeof(SecondPage));
}
When clicking the Button in the App on my Phone, I receive the information, that:
The task requires an additional App. Would you like to search the store for it? (Yes/No)
When I hit "Yes" I get redirected to the Store, where I receive the information:
Your search for "ms-resource" had no results.
What kind of App is required by my phone? Is there another way to navigate between the pages without installing additional Apps?
The problem is that you have defined NavigateUri for your HyperLinkButton. Remove that attribute and the navigation to second page should work correctly.
In more detail, your code quite likely looks like this:
<HyperlinkButton NavigateUri="SecondPage.xaml" Click="ButtonBase_OnClick" Content="Hello"/>
And your code behind as you mentioned is this:
Frame.Navigate(typeof (SecondPage));
Now when you click the hyperlink, this happens:
But now if you remove the NavigateUri from your XAML:
<HyperlinkButton Click="ButtonBase_OnClick" Content="Hello"/>
The navigation works:
This behavior is somewhat vaguely described on MSDN:
HyperlinkButton is a control, so it has input events such as Tapped,
and it's a ButtonBase subclass so it also has a Click event. You don't
typically specify a value for NavigateUri and also handle input events
that are interpreted as clicking the HyperlinkButton. The action of
opening the NavigateUri in a default browser is a system action that
takes place without requiring any event handling.
How can i put '<3 like' in a hyperlink in windows phone 8? <3 will be appbar icon.
I have tried to put image in text block but i could not succesful.
Look at the applicationbar sample that is in every new app you create. There you can see how an image is inserted as the background for a button. When the button is clicked you can use the webclient in windows phone to start the hyperlink.
For doing th hyperlink you have to look into how to create an URL, also. But it is pretty simple.
In window phone 7.5 . I want to use yes no buttons in message box . But there is no option for yes no buttons in message box. How can i use with yes no buttons or other alternate to show caption (OK =yes and cancel =no)
Please help me.
Thanks in advance.
You can use the Coding4Fun MessagePrompt to create Yes/No message with custom buttons in this way:
MessagePrompt messagePrompt = new MessagePrompt();
messagePrompt.Message = "Some Message.";
Button yesButton = new Button() { Content = "Yes" };
yesButton .Click += new RoutedEventHandler(yesButton _Click);
Button noButton = new Button() { Content = "No" };
noButton .Click += new RoutedEventHandler(noButton _Click);
messagePrompt.ActionPopUpButtons.Add(noButton);
messagePrompt.ActionPopUpButtons.Add(yesButton );
messagePrompt.Show();
Another option is to use the Guide class from the XNA framework. There is a BeginShowMessageBox method giving you the option to pass in whatever strings you wish for the buttons.
The other option is to use MessagePrompt from Coding4fun toolkit and customize according to your needs
Yes, the problem with WP MessageBox is that it only supports the OK and OKCancel MessageBoxButton, which means that you’re limited to either an ok button or an ok and a cancel button. The YesNo and YesNoCancel enumeration values are not supported.
Basically you can try to display a semi-transparent blanking layer over the page content, and then display a custom message box on top of that. Here, you can find a complete sample.
Another option is to use a custom library like Windows Phone Assets.
I'm using WatiN testing tool and i'm writing c#.net scripts. I've a scenario where i need to change the theme of my web page, so to do this i need to click on a image button which opens a ajax popup with the image and "Apply Theme" button which is below the image now i need to click on the button so how to do this please suggest some solution.
So first click your button that throws up the popup, and .WaitUntilExists() for the button inside the popup.
IE.Button("ShowPopup").click()
IE.Button("PopupButtonID").WaitUntilExists()
IE.Button("PopupButtonID").click()
This may not work in the case the button on the popup exists but is hidden from view. In that case you could try the .WaitUntil() and specify an attribute to look for.
IE.Button("ButtonID").WaitUntil("display","")
The Ajax pop-up itself shouldn't pose a problem if you handle the timing of the control loading asynchronously. If you are using the ajax control toolkit, you can solve it like this
int timeout = 20;
for (i=0; i < timeout; i++)
{
bool blocked = Convert.ToBoolean(ie.Eval("Sys.WebForms.PageRequestManager.getInstance().get_isInAsyncPostBack();"));
if (blocked)
{
System.Threading.Thread.Sleep(200);
}
else
{
break;
}
}
With the control visible you then should be able to access it normally.
Watin 1.1.4 added support for WaitUntil on controls as well, but I haven't used it personally.
// Wait until some textfield is enabled
textfield.WaitUntil("disable", false.ToSting, 10);
I'm not using any ajax control toolkit and in the popup there is no text field as i've mentioned there is only a image and a button below it, which i need to click in order to apply that image as theme.
I wrote a post about how I do ajax synchronization, since I was having problems with WaitUntilExists: http://lebobitz.wordpress.com/2011/03/06/synchronizing-watin-and-ajax-with-jquery/