About Silverlight UserControl - silverlight

I Have attached a silver light user control (ex: FirstUserControl.xaml) into my silverlight navigation page project. If I wanna run the application, i need to show the added user control as startup page. How can I set the user control as defualt page in silverlight?
Can any one please give me the solution for this?

You can set it in your App.cs Application_Startup method:
private void Application_Startup(object sender, StartupEventArgs e)
{
// Specify the main application UI
this.RootVisual = new FirstUserControl();
}

Related

Wpf webbrowser disable external links

elI am working on a Wpf application. it contains a webbrowser where the user authenticates via Facebook. The problem is that the user is capable of clicking on links (for example: Forgot your password?) the standaard browser then open... what i want to do is to disable/block all the external links. so users can only authenticate and not navigate through the webbrowser control. I hoop you guys can help me out.
Update 1
Like suggested i can check the source of the webbrowser. So i can allow the wanted pages. but the problem are the links. they open on IE. i dont want to open them, but to block them at all
Description image
private void webBrowserFacebook_Navigating_1(object sender, NavigatingCancelEventArgs e)
{
string huidigeLink = Convert.ToString(webBrowserFacebook.Source);
MessageBox.Show(huidigeLink);
// check for allowed pages
}
Update 2
I was able to find a solution: http://social.technet.microsoft.com/wiki/contents/articles/22943.preventing-external-links-from-opening-in-new-window-in-wpf-web-browser.aspx
Very slef explanatory.. thank you guys for the help!
void Window1_Loaded(object sender, RoutedEventArgs e)
{
browser = new WebBrowser();
browser.Navigate(new Uri("http://www.google.com"));
browser.Navigating += new NavigatingCancelEventHandler(browser_Navigating);
browser.Navigated += new NavigatedEventHandler(browser_Navigated);
}
void browser_Navigating(object sender, NavigatingCancelEventArgs e)
{
//Your checks should happen here..
Console.WriteLine("Loading Webpage !!");
}
void browser_Navigated(object sender, NavigationEventArgs e)
{
Console.WriteLine("Webpage Loaded !!");
}
You can register for WebBrowser.Navigating Event.
Navigating event handlers are passed an instance of the NavigatingCancelEventArgs class. You can cancel the navigation by setting the Cancel property of the NavigatingCancelEventArgs object to true.
Or you can invoke script or browser instance to stop loading if URL navigating doesn't matches.
yourWebBrowser.InvokeScript("eval", "document.execCommand('Stop');");

WPF app cant load image and related info into second form

Hey everyone i need help with a WPF app im writing.
it consists of 2 forms a main input window and a script(pharmacy script app) window
on the main input window it has a combobox with 2 items : clicks and dischem, depending on what is chosen there it needs to load the logo of that pharmacy into the script window.
at the top of the script window it has an image control
how can i accomplish this?
private void Button_Click(object sender, RoutedEventArgs e)
{
if (PharmacyComboBox.SelectedItem != null)
new Window2(PharmacyComboBox.SelectedItem as Image).Show();
}

Is there any way to get MainWindow in custom control without using Application class?

I have one custom control which is placed inside the WPF Window,is there any possibility to get that WPF Window in Custom control and hook some events on that Window? without using Application class(ex Application.Current.Mainwindow)
Ahh... how about the Window.GetWindow method?:
private void UserControl_Loaded(object sender, RoutedEventArgs e)
{
Window parentWindow = Window.GetWindow(this);
}
Note that it won't work in the constructor, but if you use the Loaded event, it works just fine.

How to display a splash screen using Caliburn Micro

I'm using Caliburn Micro v1.3 with WPF. I would like to display a splash screen while my app loads.
I have overriden OnStartup as below but can't see how to close my splash when the base.OnStartup complete
protected override void OnStartup(object sender, System.Windows.StartupEventArgs e)
{
var wm = new WindowManager();
var vm = new StatusReporterViewModel("TEST", "information", null);
try
{
wm.ShowWindow(vm);
base.OnStartup(sender, e);
}
finally
{
vm.TryClose();
}
}
Any ideas?
Cheers
Steve
If you want to use the default WPF splash mechanism then it requires no code.
Add an image file to your WPF .EXE project and then set the properties on the image to "SplashScreen"
If your Splash Screen is an actual customized Window, you can close the SplashScreen in the OnInitialize() Method of your ShellViewModel (or if you dont have a shell, the first view model that gets activated). To get a reference to the SplashScreen in your Shell either inject it or make it a singleton

set the silverlight start page

How do I set the Startup page in Silverlight?
Not sure if am googling for the wrong terminology or it just does not seem to be mentioned anywhere.
Cheers
The term "Startup page" is somewhat ambiguous. Inside a Silverlight application you probably mean one of a few things.
The initial UserControl to load as the RootVisual
In app.xaml.cs you will find code like :-
private void Application_Startup(object sender, StartupEventArgs e)
{
this.RootVisual = new MainPage();
}
Where MainPage is the user control that is the initial root visual. You can change this is your own choice.
Perhaps though you want to set the RootVisual to one of a number of possible choices. In which case you would need to use InitParams. Something like:-
private void Application_Startup(object sender, StartupEventArgs e)
{
Type t = Type.GetType("SilverlightApplication1." + e.InitParams["StartupPage"]);
this.RootVisual = Activator.CreateInstance(t);
}
You then need to include the InitParams value in the <object> tag in the host HTML:-
<object ...>
...
<param name="InitParams" value="StartupPage=Page1" />
</object
Use the navigation framework
Another approach would be needed if you building a navigation application. In this case the MainPage will contain a Frame with a Source proeperty that would contain the initial URL to map.
With this type application you could specify alternative pages to load by simply adding a path following the # in the url of the page.

Resources