UWP programmatically remove visualstate for specific listviewitem - c#

My style is defined for the listview.
Listview items will have focus behaviour.
I have 3 types in my ListView.
One is unselectable and will also not having focus behaviour (used property IsHitTestVisible = false)
One is selectable, can have focus colors (works correctly)
One should be selectable but only should not having a focus state.
IsEnabled changes the transparancy and is unselectable so no option.
IsHitTestVisible doesnt change the transparancy but make the item also unclickable.
Do anyone have an example how I can remove only the focus behaviour but keep the rest for a specific item?

You can create a ViewCellRenderer for your listview. For Reference you can use this link:
http://blog.wislon.io/posts/2017/04/11/xamforms-listview-selected-colour

Related

How to make a WPF Checkbox control's IsChecked property truly OneWay?

I have a Grid that handles Tap events via a trigger behavior. Inside this Grid are a Checkbox and a TextBlock, and I put multiple of these Grids is in a Listview as ListViewItems.
The Checkbox's IsChecked Binds to a boolean property. What I want to achieve is that the checkbox UI itself represents the current state of this property, but if I tap on the checkmark only the grid (the parent container) handles it.
To summarize, IsChecked should follow the property I specified in the ViewModel, but the checkbox should not react to any tap events in itself and leave that to its parent. (Since I use a command as a receiver I did not find a way to access the Tap Events arguments.)
I tried IsHitTestVisible, and it messes with the visual template, same as setting Disabled (since the checkbox should behave just as it would if it were enabled).
The control itself is a TreeView, basically making indents with margins in a Listview.

Bind to IsEnabled in WPF with Caliburn.Micro

I have a series of WrapPanels within a DockPanel. I want all but the top panel to be disabled at the beginning but all panels to be visible. As the user satisfies conditions in one panel I want to enable another panel. However, I can't figure out how I can bind the IsEnabled property of the WrapPanel (or if I need to the individual elements) to a boolean in my ViewModel. Any idea?
Update2: This works amazingingly! Adding a convention for IsEnabled to Caliburn.Micro
Update: Oops I lied. It keeps resetting all of my XAML by having an object of the same type in the ViewModel.
Just realized that I can just create an instance of what I am trying to >enable/disable in the ViewModel and from that access the IsEnabled property. Not >direct but works!

Changing the color of ListView items in a ListView

Basically, I have two states which I need to maintain for ListViewItem :
Pressed
Selected
Also, I need to change the color of ListViewItem on runtime, like I would need to apply red or pink or green etc.
I searched around and found I need to do something with ItemContainerStyle, also as I need it to change dynamically I would have to switch between colors via code and not XAML.
To change the pressed and selected colors, you will need to modify the ItemContainerStyle. In Blend, right click on the ListView, then select Edit Additional Templates -> Edit Generated Item Container (ItemContainerStyle) -> Edit a Copy. Use the States panel to update the Selected and Pressed states. You will have to navigate to the appropriate element in the Document tree that controls the colors you want to change.
If you need to change the settings are runtime, you will need to databind the style properties to some sort of "ColorSettings" property. that property needs to come from either the data you are binding the listview too (add a SelectedColor property, for example), or to some sort of master settings object.

listview select item backcolor

Do I programmatically have to manage the backcolor\highlight color on a Listview's item when selected through code?
So if I do this: listView1.Items[1].Selected = true;
Do I also need to do this, so it looks highlight, as it does when selected with a mouse click: listView1.Items[1].BackColor = Color.Blue;
(and clear it when the selection changes)
I would have thought that Selected = true would also do the 'backcolor\highlighting' that happens through the mouse click. Am I missing something?
Has the control got focus? If not the default setting is to hide the selection when the control doesn't have focus - see the HideSelection property.
You do not need to handle the highlighting code yourself, but the item will only appear highlighted if the ListView control has focus. Add listView1.Select() after you select the item and see if that helps.
Otherwise, you'll need to set the HideSelection property on the ListView to false.

Prevent Multi-select in WPF Tab Control?

It appears that in a WPF TabControl the user can select multiple items, either via Ctrl-Click or Shift-Click.
Is there a property that controls this? Or do I have to handle the click/select event and explicitly unselect other items?
Thanks to Moore's comment, I was able to solve this.
Each TabItem in the TabControl.Items collection needs a control to display the content. My program is using a ListView:
tabItem.Content = new System.Windows.Controls.ListView();
When creating each ListView, set the SelectionMode property to Single.
(Why that isn't happening, if Single is the default, is a mystery...)

Categories

Resources