Winforms DotNet ListBox items to word wrap if content string width is bigger than ListBox width?

lst.DrawMode = System.Windows.Forms.DrawMode.OwnerDrawVariable; lst.MeasureItem += lst_MeasureItem; lst.DrawItem += lst_DrawItem; private void lst_MeasureItem(object sender, MeasureItemEventArgs e) { e.ItemHeight = (int)e.Graphics.MeasureString(lst.Items[e.Index].ToString(), lst.Font, lst.Width).Height; } private void lst_DrawItem(object sender, DrawItemEventArgs e) { e.DrawBackground(); e.DrawFocusRectangle(); e.Graphics.DrawString(lst.Items[e.Index].ToString(), e.Font, new SolidBrush(e.ForeColor), e.Bounds); }

How to capture a mouse click on an Item in a ListBox in WPF?

I believe that your MouseLeftButtonDown handler is not called because the ListBox uses this event internally to fire its SelectionChanged event (with the thought being that in the vast majority of cases, SelectionChanged is all you need). That said, you have a couple of options. First, you could subscribe to the PreviewLeftButtonDown event instead. Most … Read more

Select ListBoxItem if TextBox in ItemTemplate gets focus

You can trigger on the property IsKeyboardFocusWithin in the ItemContainerStyle and set IsSelected to true. <ListBox.ItemContainerStyle> <Style TargetType=”{x:Type ListBoxItem}”> <Style.Triggers> <DataTrigger Binding=”{Binding IsKeyboardFocusWithin, RelativeSource={RelativeSource Self}}” Value=”True”> <DataTrigger.EnterActions> <BeginStoryboard> <Storyboard> <BooleanAnimationUsingKeyFrames Storyboard.TargetProperty=”(ListBoxItem.IsSelected)”> <DiscreteBooleanKeyFrame KeyTime=”0″ Value=”True”/> </BooleanAnimationUsingKeyFrames> </Storyboard> </BeginStoryboard> </DataTrigger.EnterActions> </DataTrigger> </Style.Triggers> </Style> </ListBox.ItemContainerStyle> You could also use a Setter instead of a single frame animation but … Read more