listboxitem

Double Click a ListBox item to open a browser

断了今生、忘了曾经 提交于 2019-11-27 19:16:22
I have a ListBox in my wpf window that binds to an ObervableCollection . I want to open the browser if someone clicks on an element of the ListBox (just like a link). Can someone tell me how to do this? I found something with listboxviews, does it only work this way or is there a way by just using the ListBox ? Yours Sebastian You can add a style to ListBox.ItemContainerStyle , and add an EventSetter there: <ListBox> .... <ListBox.ItemContainerStyle> <Style TargetType="{x:Type ListBoxItem}" BasedOn="{StaticResource {x:Type ListBoxItem}}"> <EventSetter Event="MouseDoubleClick" Handler=

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

為{幸葍}努か 提交于 2019-11-27 11:14:16
I want to get notified when an item in a ListBox gets clicked by the mouse, whether it is already selected or not. I searched and found this: ( http://kevin-berridge.blogspot.com/2008/06/wpf-listboxitem-double-click.html see the comments) private void AddDoubleClickEventStyle(ListBox listBox, MouseButtonEventHandler mouseButtonEventHandler) { if (listBox.ItemContainerStyle == null) listBox.ItemContainerStyle = new Style(typeof(ListBoxItem)); listBox.ItemContainerStyle.Setters.Add(new EventSetter() { Event = MouseDoubleClickEvent, Handler = mouseButtonEventHandler }); } //Usage:

Select ListBoxItem if TextBox in ItemTemplate gets focus

£可爱£侵袭症+ 提交于 2019-11-27 09:17:18
I have added a DataTemplate to a ListBox class to bind my collection to: <ListBox x:Name="lstEmails" Height="259" Margin="12,0,12,41" Width="276" SelectionChanged="lstEmails_SelectionChanged"> <ListBox.ItemTemplate> <DataTemplate> <StackPanel Orientation="Horizontal"> <Label Visibility="Hidden" Content="{Binding ID}"></Label> <TextBox Width="200" Text="{Binding EmailAddress}"></TextBox> </StackPanel> </DataTemplate> </ListBox.ItemTemplate> </ListBox> This does exactly what I want it to do. Although when I click on the TextBox , the ListBox does not automatically set the associated ListItem as

C# Listbox Item Double Click Event

倖福魔咒の 提交于 2019-11-27 01:00:13
问题 I have a list box with some items. Is there anyway I can attach a double click event to each item? Item 1 Item 2 Item 3 If i was to double click Item 2, a Messagebox saying "Item 2" would pop up How would i do this? 回答1: void listBox1_MouseDoubleClick(object sender, MouseEventArgs e) { int index = this.listBox1.IndexFromPoint(e.Location); if (index != System.Windows.Forms.ListBox.NoMatches) { MessageBox.Show(index.ToString()); } } This should work...check 回答2: WinForms Add an event handler

ListBoxItem HorizontalContentAlignment To Stretch Across Full Width of ListBox

心已入冬 提交于 2019-11-26 23:21:43
问题 I have a problem with my ListBoxItem 's on a Windows Phone 8 app, while trying to get them to stretch across all the width of the ListBox . My ListBox : <ListBox ItemsSource="{Binding Events}" behaviors:ItemClickCommandBehavior.Command="{Binding EventSelectedCommand}" ItemTemplate="{StaticResource EventListTemplateSelector}"/> And its DataTemplates are in a seperate xaml resource file: <DataTemplate x:Key="EventListHeaderTemplate"> <Border HorizontalAlignment="Stretch"> <Grid Height="50">

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

Deadly 提交于 2019-11-26 16:43:50
问题 Ehm, umm, this means some lines should be two-lined in size. My boss think this is more simple solution, than limit displayed text to fit width and don't like horizontal scroll bar >_< 回答1: 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; }

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

可紊 提交于 2019-11-26 15:27:52
问题 I want to get notified when an item in a ListBox gets clicked by the mouse, whether it is already selected or not. I searched and found this: (http://kevin-berridge.blogspot.com/2008/06/wpf-listboxitem-double-click.html see the comments) private void AddDoubleClickEventStyle(ListBox listBox, MouseButtonEventHandler mouseButtonEventHandler) { if (listBox.ItemContainerStyle == null) listBox.ItemContainerStyle = new Style(typeof(ListBoxItem)); listBox.ItemContainerStyle.Setters.Add(new

How to get a ListBox ItemTemplate to stretch horizontally the full width of the ListBox?

橙三吉。 提交于 2019-11-26 09:46:49
I want to have the ListItems to extend with their orange background the full width of the Listbox. Currently they are only as wide as the FirstName + LastName. I've set every element I can to: HorizontalAlignment="Stretch". I want the background of the ListboxItems to expand as the user stretches the Listbox so I don't want to put in absolute values. What do I have to do so that the background color of the ListBoxItems fill the width of the ListBox? <Window x:Class="TestListBoxSelectedItemStyle.Window1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas

Complex UI inside ListBoxItem

强颜欢笑 提交于 2019-11-26 08:50:05
In WPF, I can add whatever UI into ListBoxItem s by providing the ListBox with an ItemTemplate : <ListBox ItemsSource="{Binding}"> <ListBox.ItemTemplate> <DataTemplate> <Border BorderThickness="1" BorderBrush="Gray" CornerRadius="8" Padding="4,0,4,0"> <Grid> <Grid.ColumnDefinitions> <ColumnDefinition Width="50"/> <ColumnDefinition/> </Grid.ColumnDefinitions> <Grid.RowDefinitions> <RowDefinition/> <RowDefinition/> <RowDefinition/> </Grid.RowDefinitions> <CheckBox Grid.Column="1" Content="Is Active Customer" IsChecked="{Binding IsActive}"/> <Label Content="Id:" Grid.Row="1" HorizontalAlignment=

How to get a ListBox ItemTemplate to stretch horizontally the full width of the ListBox?

浪子不回头ぞ 提交于 2019-11-26 02:04:53
问题 I want to have the ListItems to extend with their orange background the full width of the Listbox. Currently they are only as wide as the FirstName + LastName. I\'ve set every element I can to: HorizontalAlignment=\"Stretch\". I want the background of the ListboxItems to expand as the user stretches the Listbox so I don\'t want to put in absolute values. What do I have to do so that the background color of the ListBoxItems fill the width of the ListBox? <Window x:Class=\