I want to publish some datas via pub/sub after rendering every elements in usercontrol.
However, In userControl there's no contentrendered properties.
How can i do something after rendering every things in usercontrol ?
Related
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.
I'm trying to build a WPF control inheriting from Selector and I want to change the state of the control when one of its items are selected in the design surface. Despite hooking on a debugger, I can't seem to capture any useful events from the control. I've managed to capture it being initialised and the wrappers for its child elements being initialised around the items of the selection, but I can't see any change of state, or event being triggered when the control is selected.
Importantly, I want to detect when the item is selected either by the user selecting the control in the design view or in the markup.
I'm trying to achieve a behaviour like that of the TabControl, where selecting a tab brings it to the front and exposes any content associated with the tab. I can't fathom how it works at design-time though.
What do I need to do to detect that a control is selected?
I have a grid view which has multiple items.
Each Item is a Webview. Now My issue is that I have a ComboBox above the GridView. When I select Combobox the drop down hides behind the GridView item (i.e Webview). Now I cannot use a WebViewBrush since I have multiple WebView items inside the grid view. Any suggestions?
XAML UI is always behind a WebView window - this is a typical airspace issue. You have to use WebViewBrush for any WebViews that might obscure your XAML controls. Some alternatives include modifying your UI layout - e.g. going to a separate page to display your selector control or moving ui elements about so they don't collide or implementing all of it in HTML.
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.
I have a windows form that contains two usercontrols. One usercontrol contains two list views. The other usercontrol has a grid.
Within the first usercontrol the two list views drag and drop their contents between each other.
The grid usercontrol is setup to dragdrop onto the listview usercontrol.
The problem is that the drag drop event within the listview usercontrol always takes precedence over the dragdrop between the two usercontrols.
So if I drag from the grid usercontrol over the listview usercontrol it will execute the internal dragdrop event of the listview control.
In other words it fires this event
lv_groupActivites_DragDrop
instead of
reservationScheduleBooking1_DragDrop
Is there anyway of specifying which drag drop event should be fired?
You are dragging from the grid in one user control and trying to drop onto a specific listview on the other user control or anywhere on the other user control?
If you want to drop anywhere on the other user control, I think you will need to setup the apprporate event handler on that user control to respond. If you want to drop on to a specific listview that also accepts drag events from the other listview you will need to do extra work in your event handler on that listview to figure out where the drag initiated from.