How to override the selected item style of MahApps Panorama Control? - wpf

I am using the MahApps Panorama Control in my project by linking the Mahapps.Metro.dll so I can't change the XAML-Code of the Panorama Control directly.
I thought it would be possible to override values in my MainWindow.xaml but when I do so nothing changes or maybe I change the wrong property.
The problem with the Panorama Control is that the selected item has a white border and I can't find a way to remove this selection style. I tried several solutions like changing the style or changing the control template (How to disable highlighting on listbox but keep selection?) but my changes have no influence of the Panorama Control.
There you can see the Panorama Control XAML.

This is an issue with the way that the Styles are inherited, and it's tricky to see how the ListViewItems and ListBoxItems work together. I fixed this by inserting the following in the code behind. It does, however, lose your selected item:
var listbox = MyPanorama.FindChildByType<ListBox>();
if (listbox != null)
{
listbox.SelectedIndex = -1;
}
FindChildByType is a simple search to return the first ListBox that is found under the Panorama. If you have a search by name the x:Name of the template listbox is "items".

Related

WPF TabControl - In need of a default message before tabs load

I have a WPF TabControl who's TabItems are MEF'd in at run time. However, they are MEF'd in only when a certain item in a left-hand treeview is selected. What I'd like to do is display a centered message inside the TabControl indicating "No Active Scenario Selected". I tried adding a TextBlock inside the TabControl but what I got was a TabItem instead. Any ideas?
One way to do this is simply by putting a TextBlock on top of the TabControl and show it when the TabControl doesn't have any Tabs added.
You can bind the Visibility of the TextBlock to the HasItems property of the TabControl and use a value converter (BooleanToVisibilityConverter or your own implementation) to show and hide the TextBlock.

Tooltip for disabled TabItem

I'm wanting to have a tooltip for disabled TabItems in a TabControl. The standard way of putting tooltips onto disabled controls in Silverlight is by wrapping the control in a dummy element that has the tooltip, but I can't get at the TabItem like that. The TabItems' host control is a TabPanel, which doesn't seem to expose any useful properties.
Any ideas?
I had the same problem with putting a Toolip on a disabled menu item, i solved it by changing the VisualState of my menu item to Disabled and then disabling the MouseButton events.
VisualStateManager.GoToState(tabitem, "Disabled", true);
You'll have to be careful with other events though, because the VisualState will change according to different events. It's not a perfect solution, but it will work for certain scenarios.
Hope this helps
My current workaround for my own problem:
I've got a TabControl Behavior that finds the "TabPanelTop" template part (or left, right, or bottom depending on TabStripPlacement), along with the "TemplateTop". I add a Canvas into the TemplateTop (which is a Grid), and fill it with Transparent Rectangles whose positions (using TransformToVisual) and sizes are calculated (and updated) to be the same as the TabItems, which are the children of the TabPanelTop.
The visibility of the Rectangles is bound to the inverse of TabItem IsEnabled, and the ToolTipService.ToolTip is bound to the ToolTipService.ToolTip on the TabItem.
It's a bit scary but it works and is easy to use.

wpf listview changing selected item display behavior

I want to change the display behavior of the selected item(s) in a WPF Listview. Specifically, I want to retain the custom textblock foreground colors that I've applied and apply a border around the item.
I am able to alter SystemColors.HighlightBrushKey and ControlBrushKey to change the background color of the selected item, but I don't know how to get it to stop changing the font color or use a border instead. I've tried manipulating the control template and have also searched Google for examples of how to do this, without success.
yeah, looks like you have to go through the pain of using ControlTemplates.
Good news is that via using Expression Blend, you can get current ControlTemplate for ListView and tweak the bit that you need and use that as your default ControlTemplate.

Silverlight TreeView in ComboBox (or just a custom dropdown control)

I was wondering if I can have a ComboxBox with a Treeview as the selector rather than a list?
I note that there is a ComboBox.ItemsPanelTemplate, but I don't know what I need to do to get this to work?
I could build a control 'from the ground-up' with a separate TextBox, Button and TreeView in a PopUp control, but wondered if there is an easier way.
Lee
Are you just wanting the combobox for presentation purposes regarding the treeview?
Why not use a treeview as is and just trigger the display via visibility or animation from a button or control of some sort?
I am working on similar theme as we speak. I am using the Expander control from the Silverlight Toolkit with a TreeView control inside it. When an item is selected in the TreeView, it sets the Header of the Expander and then collapses the Expander.
Initial tests indicate it's OK but as I say, just started with it myself. Will let you know if I hit any stumbling blocks.

Sliding effect when adding new items to a WPF ListBox

I have a WPF ListBox control which displays items of an RSS feed. I occasionally check the source of the RSS feed for new items. Once I detect a new item I add it to the observable collection which immediately adds the new item to the ListBox display.
Is there a way to 'slide in' the new item from the top, pushing down the existing items? How would I achieve such an effect? Can it be done with a ListBox, or do I need to resort to my own container, such as a StackPanel and animate for example the Height of newly added controls programmatically?
I just posted an answer to this question which is very similar to yours.
WPF how to animate a list of components
It can be done with a ListBox. Use the ItemContainerStyle to style the ListBoxItems that the binding creates for you: this style can include animations, e.g. by adding an EventTrigger for the Loaded event to the Style.Triggers, and transforms. For example, in your trigger action you could animate the Height so the item expands into place, or if the height is unknown you could have your style set a ScaleTransform and in your trigger action animate the ScaleY of that transform from 0 to 1.

Resources