listboxitem

WPF ListBox ListBoxItem Binding

我只是一个虾纸丫 提交于 2019-12-23 13:09:27
问题 I am going through the Sams book "Teach Yourself WPF in 24 Hours". At one point the authors show how you can bind a ListBox's selected-item value to a property. I get that, it's pretty straightforward. But when I try to create my own ListBox control with my own ListBoxItems, I can't seem to get it to work. The ListBox that works uses a system collection as its ItemsSource property: <ListBox x:Name="FontList" DockPanel.Dock="Left" ItemsSource="{x:Static Fonts.SystemFontFamilies}" Width="160" /

ItemContainerStyle blocks ItemContainerStyleSelector

老子叫甜甜 提交于 2019-12-23 05:59:31
问题 I have the code: <ListBox Style="{StaticResource DeviceListBox}" ItemsSource="{Binding MeterList, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}}" SelectedItem="{Binding CurrentMeter, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}}" ItemContainerStyleSelector="{StaticResource DeviceListItemStyleSelector}"> <ListBox.ItemTemplate> <DataTemplate> <StackPanel Orientation="Horizontal

WPF - How do I get an object that is bound to a ListBoxItem back

半腔热情 提交于 2019-12-22 05:51:13
问题 here is what I would like to do. I get a List of objects from a database and bind this list to a ListBox Control. The ListBoxItems consist of a textbox and a button. Here is what I came up with. Up to this point it works as intended. The object has a number of Properties like ID, Name. If I click on the button in the ListBoxItem the Item should be erased from the ListBox and also from the database... <ListBox x:Name="taglistBox"> <ListBox.ItemContainerStyle> <Style TargetType="{x:Type

Stretch ListBox Items hit area to full width of the ListBox? ListBox style is set implicity through a theme

佐手、 提交于 2019-12-18 14:55:42
问题 I've looked around for an answer on this, but the potential duplicates are more concerned with presentation than interaction. I have a basic list box, and each item's content is a simple string. The ListBox itself is stretched to fill it's grid container, but each ListBoxItem's hitarea does not mirror the ListBox width. It looks as if the hitarea (pointer contact area) for each item is only the width of the text content. How do I make this stretch all the way across, regardless of the text

How to access Visibility property of the ListBoxItems

霸气de小男生 提交于 2019-12-18 06:57:57
问题 In my WPF program I have a ListBox control: <ListBox x:Name="mailsListBox" SelectionChanged="mailsListBox_SelectionChanged" > <ListBoxItem Content="..." Background="#FFF3F3F3" Margin="0,0,0,1" /> <ListBoxItem Content="...." Margin="0,0,0,1" Visibility="Hidden"/> </ListBox> How can I access Visibility property of the ListBoxItems ? My code doesn't works: mailsListBox.Items[1].Visibility = Visible; 回答1: Like this: (mailsListBox.Items[1] as ListBoxItem).Visibility = Visibility.Visible; Or you

Setting focus on a ListBox item breaks keyboard navigation

强颜欢笑 提交于 2019-12-18 04:45:15
问题 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

Set ListBoxItem.IsSelected when child TextBox is Focused

为君一笑 提交于 2019-12-17 22:54:38
问题 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=

Color a WPF ListBox item based on a property

谁说我不能喝 提交于 2019-12-17 21:14:38
问题 I have an observable collection of Song objects. These song objects have a property called "Playing" that is a bool (bad naming, I know). The songs display in a ListBox in my application. I want the song that is Playing to be colored red. I have been working with triggers all day trying to make this work. So far, I have gotten to the point where they are colored based on what Playing is set to when the song is added to the list. Is it possible to make it change when the Playing property

Double Click a ListBox item to open a browser

纵然是瞬间 提交于 2019-12-17 15:39:30
问题 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 回答1: You can add a style to ListBox.ItemContainerStyle, and add an EventSetter there: <ListBox> .... <ListBox.ItemContainerStyle> <Style TargetType="{x:Type ListBoxItem

WPF ListBoxItem Visibility and ScrollBar

不打扰是莪最后的温柔 提交于 2019-12-13 17:05:18
问题 I was hoping to collapse certain ListBoxItems based on a property of their data context. I came up with the following (trimmed for brevity) <ListBox ItemsSource="{Binding SourceColumns}"> <ListBox.ItemContainerStyle> <Style TargetType="{x:Type ListBoxItem}"> <Style.Triggers> <DataTrigger Binding="{Binding IsDeleted}" Value="True"> <Setter Property="Visibility" Value="Collapsed"/> </DataTrigger> </Style.Triggers> </Style> </ListBox.ItemContainerStyle> <ListBox.ItemTemplate> <DataTemplate>