I'm new to windows phone 7
I want to ask for your help in some code for:
Im developing and app which has multiple pages. Now I want to put it into a single page using some user control. For example my main page will have a company logo in a grid and a second grid which is empty. The second grid should display the UserControl in which i'll ask user to log in, after log in I want to display another UserControl for some list box and all. Trouble is I'm not getting how can I display and change user control in Page? Just like partial page in asp.net MVC.
Is there any function which gets executed every time user control is changed, like asp.net MVC has "OnActionExecuting". Can we create a UserControl as BaseUserControl and inherit each UserControl from it...is it possible????
Sorry I'm very new to this windows phone.
I'll try to give you some hints and code to manage your problems.
First. It is possible to do all what you want ;).
If you want to use only one page (possible not the best practice) you can change your Ui from code. If you have your Page, with MainGrid and two Grids, inside MainGrid. You can access each grid with the x:name property, you had set in xaml.
Example:
<Grid x:name="MainGrid">
<Grid x:Name="LogoGrid"/>
<Grid x:Name="ContentGrid"/>
</Grid>
Here you can add your userControl as following:
var control = new CustomUserControl();
ContentGrid.Children.Clear(); //maybe delete old Children
ContentGrid.Children.Add(control);
Handling the Events is also easy. Just build it into your UserControl, like a LoginButton and replace the old UserControl with the new one after ButtonClick.
You can simply change the user control by adding the user control as a child to the container Grid.
MyUserControl myusercontrol = new MyUserControl();
mygrid.Children.Add(myusercontrol);
or to remove,
mygrid.Children.RemoveAt(0); //if you have just one child control.
Related
I am a beginner in C# and Windows Forms, and I am trying to make a little application to manage different databases.
To do so, I would like to have a TabController with different TabPages, one for each database.
I already have a template of what will be inside of the TabPages, and I want to replicate it for every TabPage. So I would like to have a C# class for every TabPage so I can just copy/paste the template and change the data source.
The problem is Forms keeps creating Partial classes when I try to create a new form, or won't let me create a class binded to my TabPage.
Is there any way to have a TabPage have its own code ?
Thanks in advance.
Create a UserControl containing your database UI and a public "DataSource" property. Then, place one of the user controls on each tab page.
My question is as follows: my app needs to show a "Hamburger" menu in the left side, while the content right of it changes depending on the context. My initial idea was to implement it with Frames inside different Pages. I learned that the Frame itself is a reference to rootFrame so there's really no need for nested Frames to get navigation going.
However, to get the Hamburger menu on all Pages I would need to include them somehow. Is there a possibility to avoid duplicating the XAML code in every Page?
Looking into this I found UserControl. The docs are a bit hard to understand for me. Say I implemented a UserControl in XAML and named a Button in it via x:Name="HamburgerButton". Then, in myMainPage` I put something like this:
<Grid x:Name="MyGrid">
<controls:MyControl />
</Grid>
The Button in the UserControl XAML has a Click event in the code behind. How do I extend / customize the implementation of it in the MainPage that uses it? I guess I don't understand the relationships between them. Also the ContentPresenter is over my head at this moment.
You don't need the ContentPresenter. That's for when you create your own templates. Your MainView should contain your Menu buttons and a ContentControl. When a user clicks one of the buttons, you exchange the Content property of the ContentControl: For each menu item you can create an extra UserControl, one of which is always set to the ContentControl. For example, when the user clicks "Menu X" then you set the Content property of your ContentControl to UserControlX that contains all the context-related things. When the user clicks "Button Y" ... you get the idea.
You can do all this from the code-behind file of your main view. In the long run, you'll probably want to look into the MVVM pattern and bind your ContentPresenter to a property of your MainView's view model - and your buttons potentially to ICommands. But it will also work via the code-behind method.
In my asp.net application, I need to be able to dynamically add user controls based on data in a database.
For example, on page1, I will bind three elements to a repeater:
some html content
a user control
more html content.
The repeater on the page is surrounded by an updatepanel
(updatemode=conditional, childrenastriggers=false)
The user control also has it's own updatepanet
(updatemode=conditional, childrenastriggers=true)
So, what I have is something like this:
outer update panel<br/>
repeater<br/>
item 1 = html<br/>
item 2 = user control<br/>
user control update panel<br/>
user control content<br/>
/user control update panel<br/>
item 3 = html<br/>
/repeater<br/>
/outer update panel<br/>
The problem is, I don't get any events fired by my user control. I'm pretty sure I need to create the control in the page_init, but I'm a little unsure of how to do this, since I may have to create any number of user controls of different types, and place them at different locations on the page. Has anyone ever run into this problem before, and how did you solve it?
Steps
Add add a placeholder control to updatepanel.
In CS file create a instance of your usercontrol.
Add that control to placeholder.
I have a user control that consists of some textboxes and checkboxes. Once the user is finished filling the first one, they should be able to add one more form by clicking an "add another record" link button.
How can I repeat this usercontrol as the user clicks?
I am supposed to use C# only.
So, we are talking of UserControl where your fields are located (I mean, that this is a one class inherited from UserControl or Control. )
There are a lot of ways to do it. But, I think, to be mode 'code concise' is to use FlowLayoutPanel
a) Create this panel. (through visual designer i.e.)
b) When user clicks, create your control
c) add your control to layout panel.
var myControl = new MyControlWithForm();
flowLayoutPanel1.Controls.Add(myControl);
One could use flowLayoutPanel1.Controls array to process all filled forms afterwards.
I'm new to WPF but I need to implement following functionality:
I have a window that contains one Grid (might be changed to stack panel or something else). In that Grid I have 2 columns, each of them contains another Grid. Lets call them gridFirst and gridSecond. There is also GridSplitter in first column allowing to resize the columns.
I want to provide a button that will allow to separate gridFirst from this window and display it "as it is" in another window. How do I do that?
It would be nice if the new window had a same menu as the original window without me having to copy-paste (that not a good coding practise) all its code to the new window.
Thanks for answers
It sounds to me like you'd want to create a UserControl and put gridFirst in it. That way you can add your user control to your main grid and your window.
If the DataContext of your control is the same then it should look the same where ever you put it.