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.
Related
I'm using a UI-Grid control for user input in a big project at work. There are cases when the grids should be available in read-only mode, meaning that any clicks from the user should remain without effect.
I have searched the documentation as much as I could, but all I've come up with is the isRowSelectable property in the options of the grid. However, I am also using the grid as a treeView. And the expand/collapse buttons are still active.
Is there a possibility to make the grid read-only as if it had supported a "disabled" attribute the way that text inputs do? Is it possible to disable it altogether?
In the end, I have used a div acting as an overlay that I put right above the grid. It has a semi-transparent gray background, the exact dimensions of the grid, a higher z-index, a not-allowed cursor, and a no-op click handler.
Depending on whether the parent container of the grid (and the overlay) has a CSS class that says the grid is meant to be disabled, the overlay shows up and blocks the user from interacting with the grid. It's a simple solution that covers my needs.
I'm making a custom dropdown button (since the one included in wpf requires too much hacking to style right). Now that i got the button bit out of the way i need to add the drop down part.
My first thought was to add a stackpanel and use that to contain the items but it gets cut off if it leaves the borders of the grid that the button is in. Next up was the popup primitive, it gets on top of everything nicely enough but position wise it just free floats and i haven't figured out how to make it follow the button it was spawned by. I also tried using contextmenu but that seems to have no positioning controls at all and just sits where the mouse made it..
Anyways wpf is a big package and I'm just getting into it, anybody know which direction i might find what I'm looking for?
Preferred approach normally is to use a Popup. You got two very important properties with a Popup
PlacementTarget and Placement
Setup a binding for PlacementTarget on the Popup to your custom Button and then use Placement to position the Popup accordingly w.r.t to the PlacementTarget(Button)
Placement accepts an enum of type PlacementMode which gives you quite a few options to position the Popup.
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 have a ListBox that contains a number of User items that are DataTemplated to appear as UserControls in the ListBox. Each UserControl can be expanded in size. To start with, the ListBox is big enough to display them all in their unexpanded state. The problem that I have is that when a number of these UserControls are expanded together, they extend out of the ListBox's visible area. The ListBox does not recognise this fact and no ScrollBars appear, even when they are set to Visible.
I am using DoubleAnimations to alter the UserControl heights when the user clicks on a button in each one. Is there something that I have to do, or some setting on the ListBox that must be set to get it to register the size changes of the UserControls that represent its items and display ScrollBars when needed?
Edit>>>
I have tracked down the problem to a custom WrapPanel that I am using in the ListBox.ItemsPanel. When I remove it, or replace it with a standard WrapPanel, ScrollBars appear when required. I got the code for the Panel from a good article about creating custom WPF panels. Can anyone see what's missing from the code given in the article and why it might stop the ScrollBars from displaying?
I wonder whether ListBoxes normally do what you are expecting? You might try calling InvalidateMeasure/Layout on the ListBox if you know when the item sizes change, just to see?
I decided to write the custom WrapPanel code again completely and this time it worked correctly! When comparing the new version with the previous version, I could see that a + was missing from a += in a measuring calculation and so the Panel thought that the items were much smaller than they really were... hence no ScrollBars.
So, if you have this problem, check your measuring code carefully.
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.