How do I show a new form in a Windows Phone 7 App?
I've initialized my class like this:
Jeans jeansform = new Jeans("Elwood Curtis");
However, there's no jeansform.Show() method.
Generally windows phone 7 application use a form navigation similar to a silverlight navigation application hosted by a browser. This allows the phone back button to navigate back from "pages" which have been navigated to.
Your Jeans "form" should actually derive from PhoneApplicationPage and should have a simple default constructor (not one that accepts a parameter as you have at present).
You would then navigate to your page with code like this:-
NavigationService.Navigate(new Uri("/Views/Jeans.xml?name=Elwood%20Curtis"));
Your "Jeans" page then does most of its initial configuration in OnNavigatedTo:-
protected override void OnNavigatedTo(Microsoft.Phone.Navigation.PhoneNavigationEventArgs e)
{
base.OnNavigatedTo(e);
Name = NavigationContext.QueryString["name"];
// Other code you would have otherwise run in a parameterised constructor
}
Related
I have an Embedded Web browser control in WPF application developed with prism. In Home page on left pane there is a grid implemented which has list of URL's, when double clicked new embedded browser view is resolved and added to the region. I pass URL to object such it loads the web page in web browser control. The issue I am facing here is for the first time when any url is double clicked on the life side grid, the application is freezing till the page is loaded in web browser control I have performed my implementation in xaml.cs by using dispatcher. Please find the code below..
public BrowserView()
{
InitializeComponent();
}
void WebBrowserControlView_Loaded(object sender, RoutedEventArgs e)
{
UrlStore = ViewModel.Model.Url;
string Url = UrlStore;
Dispatcher.BeginInvoke(DispatcherPriority.Background, new Action(() => { UrlLoad(Url); }));
}
private void UrlLoad(string Url)
{
//All implementations were run on background thread.
}
I am not sure why there is a lag initially. However, for later operations there is no lag.
I am working on a WPF PRISM application that has the following structure (I have simplified to explain better without additional layers). I am using Unity as my DI/IOC
AppMain - Bootstrapper
Gui - Views and View Models
Data - Data using EF.
In Gui, I have views names as below:
Home
EmployeesView
OrdersView
Reports
I have three regions in the shell.
MainRegion - Main Content
TopRegion - Navigation Menu
BottomRegion - Status Bar
I am using the following method to register views to the regions
IRegion region = _regionManger.Regions[RegionNames.MainRegion];
var mainView = _container.Resolve<Home>();
region.Add(mainView, ViewNames.HomeViewName);
region.Activate(mainView);
The first of activation happens in the Module Initialize method for Top, Main and Bottom.
After this, I am activating other views when the button are clicked. It is just code behind for now. Sample code here:
IRegion region = _regionManger.Regions[RegionNames.MainRegion];
var reportView = region.GetView(ViewNames.ReportsViewName);
if (reportView == null)
{
reportView = _container.Resolve<ReportsView>();
region.Add(reportView, ViewNames.ReportsViewName);
region.Activate(reportView);
}
else
{
region.RequestNavigate(ViewNames.ReportsViewName);
}
PROBLEM1: Any advise on how this can be done or the way I am doing is fine.
The top menu has Home, Employees, Orders, Reports buttons.
In the home page I have recent orders by the employee in datagrid as readonly.
I would like to double click to navigate to the OrderView and pass the selected order to show to the user. PROBLEM2 I am not sure where to do the navigation for this.
PROBLEM3: Another issue was if set the RegionMemberLifeTime keepAlive false, INavigationAware methods don't fire. If I don't set the KeepAlive to false, the page does not get refreshed because, the view model does not get called.
I need the pages to refresh when it is navigated to and not be stale and also handle any confirm prompts to the user when the view is navigated away from it.
Your help is very much appreciated.
it's certainly too late but…
Problem 1/2: is there a particular reason why you add content to region in module initializer?
the common way is more like -> in xaml:
<ContentControl prism:RegionManager.RegionName="MainRegion" />
and in ModuleInit.cs -> Initialize()
_regionManager.RegisterViewWithRegion("MainRegion", () => _container.Resolve<MainView>());
Problem 3:
the view has to implements INavigationAware, IRegionMemberLifetime
and to swich region, in the viewModel you do:
_regionManager.RequestNavigate("RegionWhatever", new Uri("TestView", UriKind.Relative));
But to work you have to register it in ModulInit.cs as an object with viewName, like that:
_container.RegisterType<Object, TestView>("TestView");
and a contentControl with the correct RegionName define in xaml of course
what is equivalent "frame" in C# application?
I must navigate from page to another page in windows application. I create master page and use some panel in page. I want to navigate from every panel to another page. how do i do?
you have to create a new window in a project and create an instance and then in a code when sb will click the nav element you need to create an instance of than window class and than invoke using method showWindow()
thank for your answer. but I get find my answer!:)
in master page , should use some panel and create user control.
you design whatever you want in user control, and in button_click in master page, get instance from user control and add to panel.
this codes are:
private void button_Click(object sender, EventArgs e)
usercontol1 user=new usercontrol1();
panel.controls.clear();
panel.controls.add(user);
I am developing a website that contains a number of "forms" for entering data, etc, and I plan on using Silverlight and RIA Services for managing the data within these forms. The rest of the site will be normal HTML/CSS/JavaScript.
The plan was to create a single Silverlight control with many pages and each page would represent a single form. A HTML page would display this control, but would display a specific page within the Silverlight control.
So, my questions are:
When embedding a Silverlight control within a HTML page how would have the control automatically navigate to a specific page?
After loading a HTML page, and display the Silverlight control, would it be possible to have some JavaScript tell the Silverlight control to navigate to another page?
1 - Silverlight uses URL bookmarks on the end of the URL to emulate navigation.
e.g. http://somesite.com/somepage.aspx#formname
You can also override the default behaviour of the navigation so that it can do cool things like use the bookmark parameter to dynamically specify the name of the Silverlight form you want to show.
2 - You would only need to ensure the bookmark part of your site URLs contain something the Silverlight application can interpret.
Lookup the INavigationContentLoader interface for examples of overriding the navigation with custom behaviour.I found a few articles on the subject quite easily. Try this one.
After a bit of searching I found that the "object" tag that defines the Silverlight control in HTML can have a "initParams" element within it.
So, my thought is each page that I create will only ever have one "form" therefore in the "object" tag I just set "initParams" to define which page the Silverlight control should set as the "RootVisual".
When the control loads the Application_Startup will look at the "initParams" and use that to determine what page it needs to create and assign it to the RootVisual property of the application.
James
1) One of the solutions (not the best one) would be like this:
private void Application_Startup(object sender, StartupEventArgs e)
{
var page = HtmlPage.Document.QueryString["Page"];
RootVisual = GetPage(page);
}
private UIElement GetPage(string page)
{
switch (page)
{
case "page1": return new Page1();
case "page2": return new Page2();
default: return new PageNotFound();
}
}
2) If you want to interact Silverlight control with HTML (JavaScript), then
this is called a 'Silverlight HTML bridge':
HTML Bridge: Interaction Between HTML and Managed Code
I'm currently using the WebAii automation framework to write some user interface tests against a Silverlight 3 application. I'm new to Silverlight and suspect that I'm missing some bit of information about the HyperlinkButton.
The application has a HyperlinkButton and I'm attempting to write code that navigates to the page, finds the button the page, then "clicks" that button (which will then navigate to the NavigateUri as specified in the HyperlinkButton's properties).
I can't figure out how to execute that click. The code I have thus far (simplified):
Manager.LaunchNewBrowser(BrowserType.InternetExplorer);
ActiveBrowser.NavigateTo("http://server/appname/");
var slApp = ActiveBrowser.SilverlightApps()[0];
var menu = slApp.FindName<StackPanel>("LinksStackPanel");
var linkicareabout = menu.Find.ByName<HyperlinkButton>("Some Cases");
I'd expect to see some sort of Click() action, or Navigate() method that I could invoke on the "linkicareabout" variable, but I must be missing how it's done.
What you are looking for is the User object off the HyperlinkButton. All controls that WebAii comes with have that object. This way you can invoke any user action on any control type.
linkicareabout.User.Click()
The User object supports any user action you can think of and mimic real user interactions. Check out the documention here.
I was unable to do this myself and instead, had to write my own navigation code. For Firefox and IE, you can just use HtmlPage.Window.Navigate to navigate to the desired URL.
However, Safari and Chrome need some extra work. I had to use hidden HTML components and some javascript interops.
This workaround is detailed here.
Basically, it entails adding a hidden anchor and button to the HTML page containing your Silverlight control, and then modifying the anchor and clicking the button via calls to the DOM.
HtmlElement anchor = HtmlPage.Document.GetElementById("externalAnchor");
HtmlElement button = HtmlPage.Document.GetElementById("externalButton");
if ((anchor != null) && (button != null))
{
anchor.SetProperty("href", url);
button.Invoke("click", null);
}