listboxitem

WPF ListBox Selection Color

不打扰是莪最后的温柔 提交于 2019-11-29 09:19:19
Sorry if this has been asked before, but I couldn't find a solution to what I'm looking for in the related questions that popped up, or on Google. In my application I'm trying to recreate Words New Document dialog, list on the left of items and on the right an icon with text underneath. In Word it has the orange gradient when you mouse over, and a darker gradient when you select an item. I've got most of this recreated, except for changing the background color once you select an item. Here's the code I'm using to create this: <ListView Margin="236,34,17,144" Name="listView1"

Setting focus on a ListBox item breaks keyboard navigation

淺唱寂寞╮ 提交于 2019-11-29 06:39:29
After selecting ListBox item programmatically it is needed to press down\up key two times to move the selection. Any suggestions? View: <ListBox Name="lbActions" Canvas.Left="10" Canvas.Top="10" Width="260" Height="180"> <ListBoxItem Name="Open" IsSelected="true" Content="Open"></ListBoxItem> <ListBoxItem Name="Enter" Content="Enter"></ListBoxItem> <ListBoxItem Name="Print" Content="Print"></ListBoxItem> </ListBox> Code: public View() { lbActions.Focus(); lbActions.SelectedIndex = 0; //not helps ((ListBoxItem) lbActions.SelectedItem).Focus(); //not helps either } Don't set the focus to the

Binding the IsSelected property of ListBoxItem to a property on the object from it's source

落爺英雄遲暮 提交于 2019-11-29 05:32:32
I have a WPF ListBox control and I'm setting its ItemsSource to a collection of item objects. How can I bind the IsSelected property of the ListBoxItem to a Selected property of a corresponding item object without having an instance of the object to set as a Binding.Source ? Just override ItemContainerStyle: <ListBox ItemsSource="..."> <ListBox.ItemContainerStyle> <Style TargetType="{x:Type ListBoxItem}"> <Setter Property="IsSelected" Value="{Binding Selected}"/> </Style> </ListBox.ItemContainerStyle> </ListBox> Oh, by the way, I think you'd like this wonderful articles from dr.WPF:

ListBoxItem produces “System.Windows.Data Error: 4” binding error

China☆狼群 提交于 2019-11-28 23:49:05
问题 I have created the fallowing ListBox : <ListBox x:Name="RecentItemsListBox" Grid.Row="1" BorderThickness="0" Margin="2,0,0,0" SelectionChanged="RecentItemsListBox_SelectionChanged"> <ListBox.Resources> <Style TargetType="{x:Type ListBoxItem}" BasedOn="{StaticResource {x:Type ListBoxItem}}"> <Style.Triggers> <!--This trigger is needed, because RelativeSource binding can only succeeds if the current ListBoxItem is already connected to its visual parent--> <Trigger Property="IsVisible" Value=

Set ListBoxItem.IsSelected when child TextBox is Focused

懵懂的女人 提交于 2019-11-28 20:44:25
I have a typical MVVM scenario: I have a ListBox that is binded to a List of StepsViewModels. I define a DataTemplate so that StepViewModels are rendered as StepViews. The StepView UserControl have a set of labels and TextBoxs. What I want to do is to select the ListBoxItem that is wrapping the StepView when a textBox is focused. I've tried to create a style for my TextBoxs with the following trigger: <Trigger Property="IsFocused" Value="true"> <Setter TargetName="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type ListBoxItem}}}" Property="IsSelected" Value="True"/

WPF - How to combine DataTrigger and Trigger?

筅森魡賤 提交于 2019-11-28 19:31:32
问题 NOTE I have asked the related question: How to combine DataTrigger and EventTrigger? I have a list box containing several items. The item's class implements INotifyPropertyChanged and has a property IsAvailable . I use that property to indicate unavailable options in the list using a different colour. However, if a selected item is not available, then the foreground colour should be red. <ListBox> <ListBox.Resources> <DataTemplate DataType="{x:Type local:InstitutionViewModel}"> <TextBlock

C# Listbox Item Double Click Event

烈酒焚心 提交于 2019-11-28 06:09:58
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? 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 Donut WinForms Add an event handler for the Control.DoubleClick event for your ListBox , and in that event handler open up a MessageBox

WPF ListBox Selection Color

孤者浪人 提交于 2019-11-28 02:44:02
问题 Sorry if this has been asked before, but I couldn't find a solution to what I'm looking for in the related questions that popped up, or on Google. In my application I'm trying to recreate Words New Document dialog, list on the left of items and on the right an icon with text underneath. In Word it has the orange gradient when you mouse over, and a darker gradient when you select an item. I've got most of this recreated, except for changing the background color once you select an item. Here's

ListBoxItem HorizontalContentAlignment To Stretch Across Full Width of ListBox

蹲街弑〆低调 提交于 2019-11-27 23:51:15
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"> <Grid.ColumnDefinitions> <ColumnDefinition Width="*"/> <ColumnDefinition Width="6*"/> </Grid

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

别来无恙 提交于 2019-11-27 22:12:59
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 >_< 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();