mouse click expander + select item issue in listview - wpf

I have a list view in which each list view item is an expander control. Now when I click on expander to open or close it, I want the item to be selected also. But its not happening. Only expander expands.
Looks like my event from expander is not reaching to the list view.
Any idea how to do it?
Thanks

Inside the "ListView" set the container style like this...
<ListView.ItemContainerStyle>
<Style TargetType="{x:Type ListViewItem}">
<Style.Triggers>
<Trigger Property="IsKeyboardFocusWithin" Value="True">
<Setter Property="IsSelected" Value="True"/>
</Trigger>
</Style.Triggers>
</Style>
</ListView.ItemContainerStyle>
Got answer from:
Link

Related

IsMouseOver trigger for DockPanel not firing unless children are hovered over

This question has been asked a couple of times before, but at this time, none of the answers I've found turned out to be working.
So I have a custom DockPanel with 2 child elements inside, 1 TextBox and 1 Image.
I intended to have the DockPanel change color on hover, so I put a Trigger inside of it. But currently, it only changes color if I hover over the children, whereas a hover over whitespace between elements doesn't do anything.
I've read similar posts which mentioned using isHitTestVisible, but it doesn't do anything.
Short version of my code is the following:
<DockPanel>
<!-- Change color on mouse hover -->
<DockPanel.Style>
<Style>
<Style.Triggers>
<Trigger Property="DockPanel.IsMouseOver" Value="True">
<Setter Property="DockPanel.Background" Value="#FFe6ffe6"/>
</Trigger>
</Style.Triggers>
</Style>
</DockPanel.Style>
<StackPanel Orientation="Vertical" DockPanel.Dock="Center">
<!-- TextBox and Image code here -->
</StackPanel>
</DockPanel>
Add this to your dock panel style.
<Trigger Property="DockPanel.IsMouseOver" Value="False">
<Setter Property="DockPanel.Background" Value="Transparent"/>
</Trigger>

xctk:IntegerUpDown custom style to hide ButtonSpinner

On the xctk:IntegerUpDown, I would like the textbox border and the ButtonSpinner to only be visible when focused or mouseover.
It is easy enough to turn the border on/off using a <Style.Triggers> section.
It is also possible to control the ShowButtonSpinner property.
However, the content of the TextBox jumps to the right if I set ShowButtonSpinner=False.
I would like to simply hide the ButtonSpinner without TextBox contents jumping around.
Like this:
How can I get access to the appropriate property?
your question helped me to find ShowButtonSpinner property which I needed to hide up and down buttons
i can suggest a workaround with setting a fixed Padding for content when buttons are hidden. Value 0,0,17,0 seems ok to me (Win7, wpf toolkit version v2.6.0.0)
<xctk:IntegerUpDown.Style>
<Style TargetType="xctk:IntegerUpDown">
<Setter Property="Padding" Value="0,0,17,0"/>
<Setter Property="ShowButtonSpinner" Value="False"/>
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Padding" Value="0"/>
<Setter Property="ShowButtonSpinner" Value="True"/>
</Trigger>
</Style.Triggers>
</Style>
</xctk:IntegerUpDown.Style>
another simple thing is to align text to left side via property
<xctk:IntegerUpDown TextAlignment="Left"/>

TextBox Inside ListView WPF

I have a TextBox inside my ListView. When I click on the textview, the SelectionChanged event of ListView is not fired.
Is there a way to fire that, so that the ListView item is selected?
Despite the fact that you have not asked a good question, I think I understand your problem. I'm assuming that when you said textview, you actually meant Textbox and that your problem is that your ListViewItem is not changed to the item that contains the TextBox that you clicked on. If this is so, then adding this Style should do the trick:
<Style x:Key="ListViewItemSelectionStyle" TargetType="{x:Type ListViewItem}">
<Style.Triggers>
<Trigger Property="IsKeyboardFocusWithin" Value="True">
<Setter Property="IsSelected" Value="True" />
</Trigger>
<Trigger Property="IsKeyboardFocusWithin" Value="False">
<Setter Property="IsSelected" Value="True" />
</Trigger>
</Style.Triggers>
</Style>
While it looks strange, the second part is to ensure that the item remains selected after it loses KeyboardFocus.
You haven't provided any code, but at a guess, you haven't handled the event:
<ListView SelectionChanged="MyEventHandler" ...
</ListView>

Mouseover to select item in listbox in WPF

I am relatively new to WPF, but I would like to know how can I enable a listbox to select an item based on a mouseover event instead of the button click. I would like the item to be selected when the mouse is over the selected item, without having to press click first.
Thank you
You may write a simple ListBoxItem Style with a Trigger on the IsMouseOver property that sets the IsSelected property:
<ListBox>
<ListBox.ItemContainerStyle>
<Style TargetType="ListBoxItem">
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="IsSelected" Value="True"/>
</Trigger>
</Style.Triggers>
</Style>
</ListBox.ItemContainerStyle>
</ListBox>

Customize Expander to expand on mouse enter

I am using Expander in WPF to display my data. The default style for the Expander control contains a toggle button which shows/hides my content when I click on it.
How can I modify the style so that it expands when I hovers the mouse over the header and collapse when I move away?
Barebone setup should be this:
<Style TargetType="{x:Type Expander}">
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="IsExpanded" Value="True" />
</Trigger>
</Style.Triggers>
</Style>
(Applies to the whole expander, not just the header. That would probably require messing with the template.)
It is possible to use databinding between isExpanded property an ismouseover:
IsExpanded="{Binding IsMouseOver, Mode=OneWay, RelativeSource={RelativeSource Self}}"

Resources