Creating a mailto: hyperlink in Silverlight Out Of Browser app - silverlight

Is there a way to create a mailto: hyperlink in a Silverlight 4 OOB app? Thanks!
Edit: based on some of the discussion, an acceptable answer would be a different way than using the HyperlinkButton, or a way to use the HyperlinkButton without having the extra popup in IE.

Ideally it would have been nice of you to post some code, as I have no idea whether the email address is known/determined at design-time or run-time, but nonetheless:
In XAML:
<HyperlinkButton x:Name="mailButton" NavigateUri="mailto:somedude#example.com" TargetName="_blank"></HyperlinkButton>
In C#:
HyperlinkButton hbtn = new HyperlinkButton();
hbtn.Name = "mailButton";
hbtn.TargetName = "_blank";
hbtn.NavigateUri = new Uri("mailto:somedude#example.com");
parent.Controls.Add(hbtn);
In a situation in which you don't know the email address at design time, it's relatively straightforward to assign the value of the NavigateUri property within a method.

I posted a solution to this issue on CodeProject
http://www.codeproject.com/Answers/383879/Silverlight-mailto-HyperlinkButton-always-opens-an#answer2
Essentially, instead of using the default behaviour add a click event and then call javascript location.href. This stops the extra browser window opening.
private void TestLink_Click(object sender, RoutedEventArgs e)
{
//Only run the click event if in browser because this will not work OOB
if (Application.Current.IsRunningOutOfBrowser)
return;
var cmd = String.Format("location.href='mailto:test#test.com?subject=blah&body=something';",
HtmlPage.Window.Eval(cmd);
}

Related

Dynamically Change Content by clicking RibbonPane using Prism

I'm using Microsoft Ribbon and Prism to develop my application. I have in my main window 2 regions: one for the ribbon and the other to inject a view depending on the button clicked in my ribbon.
That works pretty good, but I would like to have the same functionality if I click a specific ribbon tab.
Has anyone done anything like this using Prism?
As you wanted, here is the code using a Button. This code is in the VM of the Ribbon...when the button is clicked the event goes to OnShowConfiguration. This method load a new View in my GeneralContentRegion and also a new RibbonTab.
private void OnShowConfiguration()
{
loadView(PrismViewsNames.GeneralContentMainView, PrismRegionsNames.ContentRegion);
loadView(PrismViewsNames.GeneralRibbonTab, PrismRegionsNames.RibbonMenuRegion);
}
private void loadView(string viewToShow, string regionWhereToShow)
{
var regionManager = (RegionManager)ServiceLocator.Current.GetInstance<IRegionManager>();
var uri = new Uri(viewToShow, UriKind.Relative);
regionManager.RequestNavigate(regionWhereToShow, uri);
}
Myabe that helps you, Ayyappan Subramanian ;)

Wpf WebBrowser navigate throws COM exception

This is the code I was using, when I use webbrowser navigate to a page, it throws a COM exception. Is there any help here? Thanks.
Based on your comments in our conversation, your WebBrowser control is not loaded at the time you're trying to navigate. Therefore, you need to create a Loaded event handler and place your navigation code into that.
webBrowser.Loaded += WebBrowser_Loaded; // or in XAML
void WebBrowser_Loaded(object sender, RoutedEventArgs e)
{
// your navigation code here or set a flag
}
If you don't wish to go through the event route, you must, at the very least, check if the control IsLoaded prior to attempting navigation (in your particular scenario).
If the issue persists, create a new instance of the WebBrowser control and navigate through that.
webBrowser = new WebBrowser();

UI freezed instead of showing BusyIndicator in Silverlight

This is a side-related question to this other question:
BackgroundWorker in Silverlight ViewModel
I have a TabControl where I load many TabItems when the user selects menu options. I load this Tabs by binding the TabControl ItemsSource to an ObservableCollection. When I add a new TabItem to this Collection, it is shown perfectly.
The problem is I've realized that since user press a button until the tab is created (ViewModel and View creation takes a couple of seconds), the screen is freezed.
I've tried to set "IsBusy" before calling the "loadTab" but it doesn't shows up... I've tried almost everything with async calls but the UI thread is in use and it throws an exception when I create the new tab control.
Is there any trick I'm loosing??? Any ideas??? Thanks in advance.
have you seen this post?
http://www.dotnetspark.com/kb/3524-doesnt-your-girlfriend-deserves-more-time.aspx
It helps when you avoid heavy stuff in the load event and make Visible=true after you finish to load all your resources, so in that sense you avoid the user feeling tempted to click something that is not ready yet.
Not sure if it helps, but how about this idea?
public void DoStuff(Object values)
{
//your values object could be anything,
//they might even be some objects from your form
//as long as you dont modify them in the other thread
imgLoading.Visible=true;
var client = new Proxy();
client.OnWorkCompletedAsync +=client_OnCompleted() ;
client.Work(values);
}
void client_OnCompletedAsync(object sender, EventArgs e)
{
imgLoading.Visible=false;
//now you can update the UI with other stuff
}

How to get Control values from a web application that has been opened thru WPF WebBrowser Control(C#)

I have a problem.
I am calling an external application(web) through a WPF WebBrowser Control. The
application is opening properly. Now in the web application, there are certain hyperelinks.
If a user click on that hyperlink, I should be able to trap it's value.
How to achieve the same using this WEB BROWSER.. I mean, in which event , what code I need to write to get it work
Using C#3.0, WPF and Dotnet framework 3.5
Thanks
Try this.
private void _webBrowser_Navigating(object sender, NavigatingCancelEventArgs e)
{
if (string.IsNullOrEmpty(e.Uri.AbsolutePath))
{
e.Cancel = true;
string actionName = e.Uri.LocalPath;
MessageBox.Show(actionName);
}
}
Regards,
Nanda

Dynamic Application-level resources are not dynamic when hosted in ElementHost

I'm hosting a WPF UserControl in a WinForms container. Now, I want to be able to theme/skin the UserControl. To do this, I've got several resource dictionaries that define the "skins." When my app starts up I create a "new System.Windows.Application()" so that Application.Current exists. To change the theme the old skin is removed and a new skin is merged into the Application level resource dictionary at runtime. However, this does not change any of the dyanamically referenced resources in the UserControl. I tried this in a straight WPF application and it worked just fine. Am I missing something, or is it not possible to do this at all? By the way, if I add a skin into the application resources before the UserControl is initialized it will work but I cannot change the skin after that.
To repo this in the most basic way:
Create a new WinForms application. Add a WPF UserControl to the app. This is simple enough:
<UserControl ...>
<Grid>
<Button
Background="{DynamicResource ButtonBG}"/>
</Grid>
</UserControl>
Create two ResourceDictionaries, White.xaml and Black.xaml (or whatever) that have a SolidColorBrush with the key ButtonBG with respective color. In Form1.cs, add two Buttons and an ElementHost. Set the child of the ElementHost to an instance of the UserControl we just created. Wire up the buttons to events that swap the skin:
private void White_Click(object sender, EventArgs e)
{
Application.Current.Resources.MergedDictionaries[0] =
(ResourceDictionary)Application.LoadComponent(
new Uri(#"\WpfThemes;component\White.xaml", UriKind.Relative)));
}
private void Black_Click(object sender, EventArgs e)
{
Application.Current.Resources.MergedDictionaries[0] =
(ResourceDictionary)Application.LoadComponent(
new Uri(#"\WpfThemes;component\Black.xaml", UriKind.Relative)));
}
In Program.cs, ensure that Application.Current exists and set the initial skin:
[STAThread]
static void Main()
{
new System.Windows.Application();
Application.Current.Resources.MergedDictionaries[0] =
(ResourceDictionary)Application.LoadComponent(
new Uri(#"\WpfThemes;component\White.xaml", UriKind.Relative)));
...
}
Now, when the White button is clicked I would expect the button in the UserControl to turn white and when the Black button is clicked I would expect the button to turn black. This does not happen, however.
Does anyone know why? Is there a solution?
Edit: Idea: Perhaps, if there's a way to force re-evaluation of DynamicResources when the theme changes, that would work.
Thanks,
Dusty
I think this may be an overlooked issue in the WPF framework.
From what I can tell via Reflector, it appears that when the Application resource dictionary is catastrophically changed (a change that will likely have wide ranging effects like adding, removing, or replacing a skin), there is code that loops over all of the Windows in the application and forces them to re-evaluate their DynamicResources. However, other elements that I would consider top-level in WPF like ElementHosts do not get the same treatment. This leads to the behavior that I'm experiencing.
My workaround to this issue is to manually go through all of my ElementHosts individually and add, remove, or replace the skin ResourceDictionary file. It's not perfect, but it gets the job done.
Dr. WPF came to my rescue when I was trying to do something similar. He shows how to create the Application object in WinForms. Now you can reference everything as StaticResource just like in a WPF application.
http://drwpf.com/blog/2007/10/05/managing-application-resources-when-wpf-is-hosted/
Another workaround would be to create a dummy window and specify the content of the elementhost as content.
If you look into the Application and check how it handles changes of resourcedictionaries, you see that it only notifies windows..
The only thing you should remind is to never show the window (-> exception), and to close it when disposing the elementhost, so the application can shutdown properly.

Resources