whats equivalent to flex's viewstack in WPF? - wpf

I want to change the view inside stackpanel based on what user clicks from the menubar. What's the best practice to implement this?

There is no exact equivalent, but same functionality can be achieved with several containers from WPF:
with a Grid (putting all the controls inside the Grid without specifying a row or column for them and implementing a mechanism wich only allows once child to be visible at any time)
with a Custom Control derived from Panel and a Property specifying which is the active (visible) child from its children, etc.

Sounds like you could use a TabControl with the Header set to nothing

Related

What WPF control should I inherit from?

I've written a WPF control which accepts a number of UIElement objects as input and displays them docked either vertically or horizontally. The control exposes functions for enumerating, removing and inserting children, but internally I'm using a Grid to build the layout, creating a row/column for each item and inserting a GridSplitter between them. To do this I've inherited from ContentControl, and upon initialization I just set the Content property with the Grid. Everything is working as intended, but now I wonder if this might be confusing for the user of my control, as it would be counter-intuitive to have a ContentControl that has many items.
Should I be inheriting from ItemsControl instead?
Should I inherit directly from Control which is "content-agnostic"?
Is there a better way to do this?
Thanks in advance.
What you describe sounds like a Panel - basically a control which is responsible for the layout of many elements. I would consider inheriting from that.
Your mention of "docked either vertically or horizontally" leads me to believe perhaps a StackPanel would be a better fit, since it does docking as well.

Inheriting styles in custom WPF controls

I have a datagrid, and certain columns need to contain text that is linked to a detail window. So, in order to make it a bit easier on myself, I created a UserControl that is basically a Button with a control template that contains a TextBlock (I could have done this a number of other ways, I know, but I figured the button already exposes a Click event, so why not?). Things are getting a bit hairy, though, when it comes to styling: I'd like to give the text a "hyperlink" sort of format--blue text, underlined--so that it's clear they are links (also, so that they resemble to format in the legacy WinForms application I'm re-implementing). But I would also like to be able to style the text--ideally, it should grab things like text color if text color is set in a style on the parent cell.
Basically, is there an easy way to implement a custom UserControl that will a) grab styles from a parent element and b) apply its default styles in a low-priority way, i.e. only apply a specific style if there's not already one set from the parent? I know I can pass the parent's style manually through a binding, but I was wondering if there was an easier way.
It sounds like you need to create a true Control or ContentControl implementation for this, so that you can override the true styles and templates.
UserControls are not really stylable, unless you start somehow creating custom properties for binding Styles.. but none of that will be implicit.

Silverlight control layout update in runtime

I have a silverlight control that has a few element such as: Image, TextBox and a TextBlock.
The application shows a list of the same control and the controls are placed in a specific layout, in grid with rows and cols.
Now,
I would like to be able to modify all the controls layout and arrange the element differently (preferred animatedly) without reloading the control.
Does anyone know how to do so?
Thanks,
Ronny
Use the States pane in
Expression Blend 3 to define different
layouts.
Use the GoToStateAction for the objects/events that you want to trigger the change or call VisualStateManager:GoToState(this, "NewState", true) from your code behind to switch layouts.
Use FluidLayout (the wave-shaped first button first for the State Group) to animate the change from one grid col/row to another.

Encapsulating and customizing a third party WPF control

I'm interested in customizing a 3rd party control, such as Telerik's RadGridView, as a standalone control, for example adding New Row and Delete Row buttons above the grid, yet still supporting XAML manipulation of the internals of the control by the window upon which my control exists (i.e. for the window to add its own style to a column of the grid).
Is there a way to add the buttons, etc. with templates? Styles?
My current "solution" is to inherit from the RadGridView, but I'm stuck on how to add the features I need.
Thanks!
My suggestion is to use composition over inheritance.
You can create your own control (UserControl should do the work). Then you can define the layout (may be in Grid panel): buttons on the top, RadGridView bellow them, etc. For custom column styling you can use DynamicResource trick. Set the styles of the columns you want to modified with DynamicResource. This way when the control is added to the logical(visual) tree; WPF will walk up the control tree and find appropriate resource. This way in each window/page resources you can define the different resource.
Another idea that come to my mind is that you can extract the buttons as a separate control. The only reference that they will need will be RadGridView and you can use binding with element name to provide it.
I would go the custom UserControl route instead of inheritance route. Styling and theming work strangely when you're dealing w/sub-classes. Unless you're planning on duplicating and modifying Telerik's ControlTemplates and DataTemplates, it can get pretty hairy.

When writing the xaml for my user controls should I remove grid and use dock panel or something else?

I am adding user controls in my solution. The main page of my project will have a dock panel. When writing the xaml for my user controls should I remove grid and use dock panel or what? Iam using visual studio express and WPF.
The answer is it depends on what you want your control to look like.
Remember the Grid is to help you orgainze your controls. You can define features like columns widths, row heights, and other styling.
While a dock panel is to help dock your control to a part of the form or another.
So it depends on what you want your control to look like. You can nest a grid in a dock panel and vice versa. There is no set rule. It is really up to you.
Inside your user controls, use whatever type of panel makes sense for the contents of that control. In the main page, you set the DockPanel.Dock attribute on your user control, but that is independent of what's inside the user control.
It really depends on what you want to do.
Your top level may not even be a panel. For example, if you only want one control in the user control, then you really don’t need the panel.
Also, in some cases, even with composite controls, you may want to put something other than a panel as the top level control, for example, an expander.
Further, if you want to create a control that is very similar to another control, but behaves a little different, you may not even want to use a user control and instead inherit from an existing control. An example of this would be a numeric textbox that inherits from a textbox but adds keypress filtering.

Resources