listboxitem

How to set ContextMenu of a bound item?

≡放荡痞女 提交于 2019-12-06 01:28:32
问题 I am trying to achieve the following: <Style TargetType="ListBoxItem"> <Setter Property="ContextMenu"> <Setter.Value> <ContextMenu> <MenuItem Name="mnuEdit" Header="_Edit" Click="MenuItem_Click" /> </ContextMenu> </Setter.Value> </Setter> <Style> But it throws the following exception: Cannot add content of type 'System.Windows.Controls.ContextMenu' to an object of type 'System.Object'. Error at object 'System.Windows.Controls.ContextMenu' in markup file blah blah blah 回答1: Try this instead:

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

穿精又带淫゛_ 提交于 2019-12-05 07:36:41
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 ListBoxItem}"> <Setter Property="HorizontalAlignment" Value="Stretch"/> <Setter Property="Template"> <Setter

How to group ListBoxItems by first letter in WPF using XAML?

末鹿安然 提交于 2019-12-04 22:54:58
问题 First, here is the previous post that deals with the ListBox AccountListBox data binding to my ObservableCollection<Account> Accounts from the AccountsCollection.cs class. So now I have a binding object AccountsCollection and a DataTemplate named AccountTemplate for my ListBox defined in the resources: <Window.Resources> <controller:AccountsWindowController x:Key="AccountsCollection" /> <DataTemplate x:Key="AccountTemplate"> <DockPanel> <Button Name="EditButton" DockPanel.Dock="Right" Margin=

ListBox with single select and also unselect on click…?

我是研究僧i 提交于 2019-12-04 22:53:52
I need a listbox that selects on first click and un-selects on second click, so that only zero or one item is selected at any time. The select/unselect is implemented in the listbox (with SelectionMode="Single") when you hold down crtl, but unfortunately, none of my users can be expected to know that. With SelectionMode="Multiple" we have the exact functionality I want, except that you can select more than one item... More background: I want the user to first choose which installation to log into, then to give credentials (and some other choices) To achieve this I have used a listbox with

WPF. ListBox item style

自作多情 提交于 2019-12-04 16:23:28
I have problem with ListBox item style, I create two styles and do not know to use it together. 1st style is for ListBox item size, mouse over color and so on, or second is for item background (Alternation count). If I leave one of them they work fine, but how to make them work together? Or maybe I could it write in one style? My code is: ..... <Style x:Key="Style2" TargetType="{x:Type ListBoxItem}"> <Setter Property="SnapsToDevicePixels" Value="true"/> <Setter Property="OverridesDefaultStyle" Value="true"/> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="ListBoxItem">

C# Listbox set selected item

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-04 12:36:43
问题 i have a C# listbox with the values Profile 1 Profile 2 Profile 3 I want to have Profile 2 selected when the form loads. How do I do this? 回答1: Set the ListBox.SelectedIndex property in the Form.Shown event. For example: public Form1() { InitializeComponent(); // Adding the event handler in the constructor this.Shown += new EventHandler(Form1_Shown); } private void Form1_Shown(object sender, EventArgs e) { myListBox.SelectedIndex = 1; } 回答2: Put following code in Form.Loaded event: listBox1

How to group ListBoxItems by first letter in WPF using XAML?

妖精的绣舞 提交于 2019-12-03 14:29:47
First, here is the previous post that deals with the ListBox AccountListBox data binding to my ObservableCollection<Account> Accounts from the AccountsCollection.cs class. So now I have a binding object AccountsCollection and a DataTemplate named AccountTemplate for my ListBox defined in the resources: <Window.Resources> <controller:AccountsWindowController x:Key="AccountsCollection" /> <DataTemplate x:Key="AccountTemplate"> <DockPanel> <Button Name="EditButton" DockPanel.Dock="Right" Margin="3 0 3 0" VerticalAlignment="Center" Content="Edit" /> <Button Name="DeleteButton" DockPanel.Dock=

C# Listbox set selected item

大城市里の小女人 提交于 2019-12-03 08:06:58
i have a C# listbox with the values Profile 1 Profile 2 Profile 3 I want to have Profile 2 selected when the form loads. How do I do this? Set the ListBox.SelectedIndex property in the Form.Shown event. For example: public Form1() { InitializeComponent(); // Adding the event handler in the constructor this.Shown += new EventHandler(Form1_Shown); } private void Form1_Shown(object sender, EventArgs e) { myListBox.SelectedIndex = 1; } Put following code in Form.Loaded event: listBox1.SelectedItem = "Profile 2"; listBox1.Items.Add("Profile 1"); listBox1.Items.Add("Profile 2"); listBox1.Items.Add(

How can i know if a ListBoxItem is the last item inside a Wpf's ListBox?

眉间皱痕 提交于 2019-12-02 11:42:12
问题 How can i know if a ListBoxItem is the last item of the collection (in the ItemContainerStyle or in the ItemContainer 's template) inside a Wpf's ListBox ? That question is because I need to know if an item is the last item to show it in other way. For example: suppose i want to show items separated by semi-colons but the last one: a;b;c This is easy to do in html and ccs, using ccs selector. But, how can i do this in Wpf? 回答1: As it seems to be rather difficult to implement an "Index"

How can i know if a ListBoxItem is the last item inside a Wpf's ListBox?

∥☆過路亽.° 提交于 2019-12-02 07:51:56
How can i know if a ListBoxItem is the last item of the collection (in the ItemContainerStyle or in the ItemContainer 's template) inside a Wpf's ListBox ? That question is because I need to know if an item is the last item to show it in other way. For example: suppose i want to show items separated by semi-colons but the last one: a;b;c This is easy to do in html and ccs, using ccs selector. But, how can i do this in Wpf? As it seems to be rather difficult to implement an "Index" attached property to ListBoxItem to do the job right, I believe the easier way to accomplish that would be in MVVM