We have a screen that shows a grid inside a tab control. There's one grid instance, and it needs to always be visible, regardless of which tab you're on. (We repopulate its content when you switch tabs, but it's always the same grid instance.) The UltraTabControl has a "shared controls page" that seems perfect for this, and most of the time it works great.
However, when the tab control has no tabs at all, Infragistics does not show the shared controls. We need the grid to be visible even if there are no tabs at the top of the tab control.
Is there a way I can get the shared content to show, even when there are no tabs?
Apparently there's no way to do this directly. I wound up working around it by re-parenting the content when there are no tabs.
For example, suppose I have a panel (panel1) that contains the tab control (ultraTabControl1), whose shared page (sharedPage1) normally contains a grid (grid1). I run code like this every time I change the list of tabs:
var anyTabs = ultraTabControl1.Tabs.Count > 0;
ultraTabControl1.Visible = anyTabs;
grid1.Parent = anyTabs ? sharedPage1 : panel1;
Inelegant, but at least it works.
A better way may be to use the UltraTabStribControl.
That's basically just the header of a TabControl without the content Panels.
With that you just need to place a Tabstrip on top and the grid below. But ff you have other controls which are shown dependent on the tab then you would have to hide/show them manually or stick to the full TabControl.
Related
Summary
How do I add a placeholder in my Toolbar so that I could dynamically change its content?
Detail
The Toolbar in my application shows a dropdown. Depending upon the current selection in the dropdown, I need to select what other items will be shown in the Toolbar. So I went ahead and added the dropdown, followed by a ContentControl, whose content I dynamically select using a TemplateSelector.
This setup works fine except that the Toolbar treats the entire ContentControl as a single item and moves it to overflow panel if there isn't enough space to display all of it. Here's a snapshot:
Notice how it doesn't display any of the ContentControl contents even though there is enough space to display at least the first 5 elements.
Note: I have tried it with wrapping my items inside ToolBarOverflowPanel too, but that doesn't do any good. I think I understand why it behaves this way, but need a way around it. I have also tried using WrapPanel instead of ContentControl, but WrapPanel doesn't support templating.
I have a WPF RichTextBox in my application that sits in Grid. It gets updated every second or two as it displays logs (though sometimes there are no logs for up to a minute depending on the load).
The grid is not always visible, as it sits in its own tab. If the user is on another tab, the logger is not visible.
My problem is that I want the RichTextBox to scroll to the end every time a new paragraph is added. It seemed simple as there is a 'ScrollToEnd' method on the RichTextBox control and so I call that method every time text is added to the control.
The problem is that that method only works if the control is visible, if the user is on another tab, the RichTextBox will not scroll to the end and it looks weird when you click on the tab with the logger and after a couple of seconds or longer it scrolls to the bottom when it should already be at the bottom.
Is there a way around this annoying "feature" of the control? I would like to ALWAYS have the RichTextBox be at the bottom unless the user is manually taking control of the scroll bar.
Thanks!
By default, the TabControl actually doesn't change its contents visibility, it removes them from the view completely when you change tabs and then "re-attachs" them when you navigate back to the previous tab.
That's why the Visibility change doesn't get fired. Instead, you should handle the Loaded event, which should get fired right before the view is re-rendered.
Is there a reason you cannot simply call ScrollToEnd in response to the text box becoming visible? That seems like the simplest approach. Did you try it and run into an issue?
Edit: If you are using a TabControl, each TabItem has an IsSelected property you can bind to from the ItemContainerStyle. You could probably scroll your text box in response to the tab becoming selected.
As a separate note: if you are planning to make a custom control for this, here are some things to consider.
I wrote an auto-scrolling version of a FlowDocumentScrollViewer. (I never needed a RichTextBox specifically, but they display similar content.) I can tell you that there are a lot of things to account for, such as knowing when and when not to auto-scroll based on what the user is currently doing.
For example:
If the user takes over the scrolling themselves via the scrollbar or mousewheel, you don't want the control to fight with them.
If they start selecting text, you don't want to scroll it away from them mid selection.
If they scroll to the bottom, you probably want it to start auto-scrolling again.
Also, determining what the user is doing to begin with can sometimes be a complex process on its own.
I have the main.xaml where I have a ribbon with some tabs on it. Basically I have an Articles Tab, Categories Tab, Keywords Tab etc. What I would like to be able to do is, once I click on the Articles tab, I load the datagrid with the Articles, once I click on the Categories Tab, I load the datagrid with the Categories, and the Keywords the same thing. I was thinking of creating 3 datagrids, and once a tab is clicked I hide/remove the other 2. Is this the correct way to do it, and if it is how can I achieve this?
Thanks for your help and time
ok solved
I only needed this
dgCategories.Visibility = Visibility.Collapsed;
I haven't used a ribbon, but in a normal tab control you can set the SelectedContentTemplateSelector property to a DataTemplateSelector. This will provide a given template to the content that you have currently selected. This means that you don't have to worry about adding / removing controls as this will be handled by WPF.
In general when you are faced with changing display of content then I would recommend using a template selector.
First of all, I do not feel completely educated on how to navigate between multiple "pages" of a window.
For example, I have a Window called MainWindow. Inside of this, I have a header and a footer. In the middle is a panel which contains content.
This panel will originally contain content A. Upon clicking something in A, I want to remove A from view and show a new panel with content B. However, I want B to be shown in the same window (i.e., not hide the window and open a new one). Is hiding/showing these panels the correct way to go about it?
If using the panel switching mechanism is the correct way, then I am worried about resource management. If I set panel A to not be visible, and panel B to be visible, will I still have resources from both panels loaded? If I have a large number of panels to switch between, I would not want to load content for all of them, but rather the active one.
How would I go about making sure that I am correctly handling resources and memory between these different views?
If I have the completely wrong idea about how to switch views within a single window, please let me know.
Thanks.
Instead of toggling visibility off and on, you should put a contentControl and switch it's contents to different UserControls.
That way there's no reference to the UserControl that's offscreen, and you can handle memory issues better.
One alternative is to just use a single ContentPresenter, and put your individual "panels" in there, but only one at a time.
Instead of flipping visibility, you could use Data Binding to change the bound content within the ContentPresenter. This would only leave a single "view" in place at a time, preventing the neeed for "a large number" of panels to be loaded.
I'm converting an app from ASP.NET WebForms to WinForms. There is one asp.net page which contains a ListView/Repeater that contains several custom controls, which in turn contain a ListView with other custom controls. Basically the layout looks like a TreeView, but on each node/leaf there are few controls like comboboxes, etc.
When this is in ASP.NET, the page automatically lays itself out, so it is several screens tall - if I add 20 buttons into a Panel, it will grow and the browser will get scrollbars.
I'd like to do the same thing in a WinForms application - so I'll have a user control that will contain a lot of controls in a some variation of Panel (Flow, Table layout), and the controls might have another controls inside them, etc.
The problem is, that when I make winforms app, each control has specific height in the design time. I'd like some user controls to be able to grow with their contents - so they'll add up. In the main Form, there should be a vertical scrollbar, just like in the web browser when the generated page is taller than the screen.
I'd just like to get some general pointers in the right direction. Thanks.
Use Anchor and Dock container properties.
Yes, to expound on Anchor and Dock...try this
-Place a Panel on an empty form, and set its dock property to Top
-place a textbox in the panel, and Dock it to Full...it should fill the whole top panel
-Place a splitter on the form, and if not already docked correctly, set its dock to top
-place another panel below the splitter, and set its Dock to Fill
-place another textbox inside the lower panel and fill it as as well
Now you have a form with two resiable textboxes and will resize when the form does.
*you may have to set the textbox MultiLine property to true but not sure.
Hope this helps.
Anchor the controls to the parent. Anchoring all four sides will cause it to stretch.
If the Anchoring and Docking answers don't work for you, there is another option. It's not pretty, but you can access a control's properties and change them dynamically during runtime. You'd do something like: if(listBox.Items.Count > [yourVal]) listBox.height = [yourFormula] or something.
It's been a while since I've done a Win Form (and I don't have my IDE fired up at the moment) but I'm pretty sure there's even a ScrollPanel or other scrolling control that you can set on your form.
That said, when you're working with WinForms, the less scrolling you can make your users do, the better.