C#/XAML Windows 8 AppBar by command? - c#

I apologize if this is a simple question. I'm very new to XAML, and I'm trying to understand app development more.
Basically, I have a section on the bottom of the display reserved for a pop-up AppBar. From what I understand, this pops up on an edge swipe, but I'd like to use some sort of a call to bring it up. This way I can have various varieties of the AppBar pop-up when the situation calls for it.
How would I go about accomplishing this?
OR, is there another approach that might work better?
Thanks for your time!

The page has a BottomAppBar property (<Page.BottomAppBar>). Here you can enter a AppBar control and inside of it any XAML you want. Then you can show and hide anything through the Visiblity property from code. So - you can for example add two Gridcontrols in the AppBar and always display one of them.

If you're looking to create multiple AppBars for use on the same page, you'll have to do so in the code behind. See this link:
http://msdn.microsoft.com/en-us/library/windowsphone/develop/ff431786(v=vs.105).aspx
Once you've created them, set the IsVisible property to true/false to show/hide them.

Related

Change parent of a control in a size trigger in UWP

I'm creating a Windows 10 Universal app, there are two panels in my main page.
In tablet/desktop mode, both are visible at the same time (just two simple Grids, one fills the left side and the other one fills the right side)
However, in phone mode, there's a pivot and user can swipe between panels.
(I could use SplitView and hamburger menus which work easily in both Tablet/Desktop and Phone modes, but a pivot makes more sense in my case)
So, What I currently did is, I have two instances of each panel. PhonePanel1 and PhonePanel2 are two grids inside two pages of my pivot control, and TabletPanel1 and TabletPanel2 are two grids which can be shown side by side. and I use AdaptiveTriggers to detect page width and switch between these two view methods.
However, having two instances of each panel is not a good approach, because those are showing basically the same content.
Is there any better approach to do this? Maybe changing Grid's parent when triggers are changing view mode? or something better?
The only way to change the parent that I can think of is to write some code behind that will render them in the new location. A suitable solution may be to defer the loading of the controls until they are needed.
x:DeferLoadStrategy=”Lazy“
If you add this property to your controls that are duplicated, they will only be loaded when required. So on a phone the PC/Tablet view should never be loaded, unless the user is running in Continuum on an external display.
On a PC you may still end up with both loaded (If the user resizes the window) - On a PC there are usually more resources so it's less of a problem there in most cases.
I looked into the code behind approach to move the controls to a different parent and I think honestly it's premature to do that when it might not even improve performance.
I have gone for the Defer Load Strategy property and found performance to be fine, and it requires very little code. My duplicate controls are sharing the same ViewModel so I pretty much just added the property to ensure resources are only used when essential.
There is nothing wrong in your approach. To reduce memory usage, when adaptive trigger happens for example on the phone, set TabletPanel1 and TabletPanel2 visibility to collapsed.
If all panels use the same datacontext then leave it as is, if not set datacontext for collapsed controls to null.
You could create each of your panels as user controls then you've only need to define the contents once but each control could be included in each of the layouts you want.

WPF C# Updating label on second window

Hi guys I have a problem
i need the info I enter in a text box on my main window to update a label on my second window called script.
The text box name is client and the label name is client-label
I have tried many different ways to do this and still not coming right
how can I do this?
PS. I am new to the programming world so please give me step by step instructions anywhere possible :)
Pertinent to your requirement (i.e. two WPF windows with sync controls), it will require quite a bit of coding. Better (simpler) way is to create a pseudo-window, i.e. just a nested layout Grid within you main window containing all controls pertinent to that second window (you can set its visibility to collapse/visible in order to "simulate" pop-up window), and update a second TextBlockon .TextChanged event of the first TextBox (using code behind). Alternatively, you can apply data binding technique is XAML of the same single window.
Note: you can implement a splitter control to resize two 'sub-windows'.
In case you do prefer to implement second window, then refer to this example: Data Binding between two TexBoxes in different windows
Rgds,
The "correct" way for this would probably be to have a view model for each view part in your gui and have them communicate through events.
The Prism framework for WPF will help you with most of the plumbing for this.
Se more about Prism here: http://compositewpf.codeplex.com

What would be the best course of action for display different form in a single Winform?

Here's a screenshot of my application:
Basically, depending on what option is selected I'd like to show another 'content' which can be a buttons, or forms or whatever.
What would be the best choice for this? Using MDI? I'm really new to this type of thing.
This scenario lends itself well to tab pages, as you'd find on a TabControl.
However, since you already have a mechanism for switching between the content, you might prefer to create a series of Panels whose Dock property is set to DockStyle.Fill. When the user clicks the appropriate heading, you simply need to show the appropriate panel and call BringToFront() on it. This is essentially what the tab control does internally, anyway.
Don't forget to use SuspendLayout() and ResumeLayout() appropriately to reduce flicker, which can be a huge problem in WinForms applications, especially when there are lots of controls.
You can position a TabControl where the buttons are not visible and control it from your buttons.

How to design the UI for settings according to different options in C# WinForm?

This is a .NET winform application question.
I come to this design from time to time. A simple form. On top of the form you have a list of options to select. According to different option chosen, the body of the form displays a unique panel of setting detail.
How to design this UI in Visual Studio neatly? I have two ideas. First idea is to have many panels, each panel contains setting controls. In runtime, hide all panels but the one according to the selection of option. In this solution, it is hard to organize the controls of the form in VS designer. You need to set the form big to hold all the panels. Panels are put one next to each other. There are many runtime loading code to write. For example, when loading the form, you need to hide panels, reset the form size. When you pick an option, you need to relocate the panels and show/hide them. Tedious!
Second idea is to use TabControl. TabControl is good because the tabs are well organized for you. You don't need to relocate panels and resize the form. All you need to do in runtime is to select the right tab according to options. One thing, you need to hide parts of the TabControl from user because after all it is not a real TabControl. Hiding the tab buttons of the TabControl is not hard but I find that after that there is always a big gap between the tab area and the following part on the form.
Dose anyone have a decent way of designing the UI? Maybe not using panels or TabControls but some smarter way? If TabControl is used most of the time, how to hide and show the tab parts of the TabControl and how to set the margin and border size of the TabControl so no big gap exists? Many thanks to any answer and suggestion.
When I need to do this, I put each group of controls in its own UserControl, and then I can use something else to switch between them. See, for example, Implementing a paged Options dialog on my blog.
I suggest you create UserControls for each of your "setting details" and when the user selects an option you load the accordant UserControl. You might have to adjust the forms size, but therefore you can easily manage all the "setting details" in your IDE.
Using user control is a good way to solve your problem. But you need set them probably in panels and play with properties "Visible" and "Dock".
You don't need to Dock them at "Fill" in design mode. You can set this property à runtime or when needed.
Hope this help.
Sounds like you need some design pattern.
Why not create a UI factory that returns your UI objects as needed/required?

Making winform switch tabs

I'm making a winform in C# using Visual Studio 2008.
Currently, I have a tabcontrol, containing 2 tabs.
In the first the, there is a button. When I click it, I must be taken to the second tab.
Problem is, I don't know how. I've tried debugging, looking into al kinds of Properties and messing around with them, but I found nothing that helps.
Does anybody here know how to pull this off?
Extra info: my variables are named tabControl1, textTab and logTab.
I'm in textTab, click on a button there and I want to be taken to logTab. That's it basically.
Did you try this?
tabControl1.SelectedTab = logTab;
You can set either the SelectedIndex property or the SelectedTab property of the tab control to switch tabs.

Categories

Resources