itemssource

Error when binding WPF combobox ItemsSource to an Array of Strings

最后都变了- 提交于 2019-12-24 06:45:49
问题 I could not set a combobox's ItemsSource to an Array. I have tried setting the DataContext to the class where the Array is found, and then setting the bindings in XAML class Car { public string[] makes; } ... public MainWindow() { Car _Car = new Car(); _Car.makes = new string[] { "Toyota", "Mitsubishi", "Audi", "BMW" }; this.DataContext = _Car; } and then in XAML <ComboBox Name="cars" Grid.Column="0" Grid.Row="0" Margin="5" ItemsSource="{Binding Path=makes}"/> It doesn't seem to do anything.

Removing an item from a WPF binding listbox

♀尐吖头ヾ 提交于 2019-12-24 04:01:14
问题 I have a WPF application with a ListBox (called listMyItems) which is successfully bound to a class of MyItems that I created. I have a List of MyItems called currentMyItems which is then assigned as ItemSource to the ListBox. It all works fine, if I add an item to the currentMyItems it pops up on the list, etc. The problem occurs when I try to remove the selected item in the ListBox. This is the code that I use: currentMyItems.Remove((MyItem)listMyItems.SelectedItem); The item disappears

SelectedValue explicit binding updates when ItemsSource change..why?

萝らか妹 提交于 2019-12-24 02:49:07
问题 I have a ListBox with an Explicit binding set to SelectedValue. SelectedValue="{Binding Path=Property, UpdateSourceTrigger=Explicit}" the ItemSource of ListBox is an ObservableCollection. When I select an item of ListBox and press 'Enter' I update the property value in this way: BindingExpression be = listBox.GetBindingExpression(ListBox.SelectedValueProperty); be.UpdateSource(); Now, I have this problem: I have to reset the ItemsSource of ListBox by specific action on my window and when call

What is causing my WPF combobox items to take so long to refresh when the itemssource is changed?

我的未来我决定 提交于 2019-12-23 04:52:45
问题 I have a datagrid (call it dat1) that has an items source bound to an observable collection of a custom type, call it TypeA. One of the properties on TypeA is an observable collection of another custom type, call it TypeB. I then have a combobox with an items source bound to dat1's SelectedItem.TypeB. So when the user selects a TypeA in dat1, the combobox shows the items in the TypeB observable collection from the selected TypeA. Make sense? The binding DOES work and it DOES update. The

Unreasonable WPF DataGrid Loading Time

一笑奈何 提交于 2019-12-22 03:59:11
问题 I've always had long loading times with WPF DataGrids, and I cannot find any similar reports online, so I suspected that I was doing something wrong. Now I am sure of it, since adding layout complexity considerably slows down execution. In a very simple layout, the DataGrid populates instantaenously, whereas the code below takes around 3 seconds to execute. In the following code, it takes ~3 seconds for 150 rows and 11 columns to load, even if each cell is not bound to any property and with

WPF: How do I hook into a ListView's ItemsSource CollectionChanged notification?

╄→尐↘猪︶ㄣ 提交于 2019-12-20 01:06:44
问题 I have a ListView that is databound to an ObservableCollection ... <ListView x:Name="List1" ItemsSource="{Binding MyList}" /> I can't seem to find any event that are triggered when the collection changes, so I'm thinking that somehow I need to hook into the collectionchanged notification somehow? I'm not really sure how to do that. Basically, when the collection changes I want to do additional work beyond what the ListView already does in updating it's list. 回答1: By default the ItemsSource is

Binding to DataContext outside current ItemsSource context

為{幸葍}努か 提交于 2019-12-19 02:23:29
问题 I have a DataSet bound to the Window.DataContext ; I also have a DataGrid : <DataGrid ItemsSource={Binding Tables[Items]}> <DataGrid.Columns> <DataGridTextBoxColumn Header={Binding Path=DataContext.Tables[Names]/Test, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}} /> </DataGrid.Columns> </DataGrid> Basically, I'm trying to bind the Header of that column to DataTable "Names", Column "Test", first row. However, I can't get it right. Note that I can bind it fine

WPF DataGrid: DataGridComboxBox ItemsSource Binding to a Collection of Collections

怎甘沉沦 提交于 2019-12-17 08:54:28
问题 Situation: I've created a DataGrid in XAML and the ItemsSource is binded to an ObservableCollection of a certain class that contains properties. Then in C#, I create a DataGridTextColumn and a DataGridComboBoxColumn and binded these to the properties of the objects inside the ObservableCollection. I can bind the DataGridComboBoxColumn to a simple Collection but what I want to do is bind it to a collection of collections of strings so that for each row the ComboBox inside the DataGrid has a

wpf datagrid drag row on Icollectionview which bind to collection

笑着哭i 提交于 2019-12-13 18:31:24
问题 I have a datagrid like this _productsPosition = new ObservableCollectionEx<NotifiedPositionInfo>(); _itemSourceList = new CollectionViewSource() { Source = _productsPosition }; _itemSourceList.Filter += new FilterEventHandler(FilteringProduct); PositionsGrid.ItemsSource = _itemSourceList.View; and when I try to drag row on this datagrid, i can obtain the index of row on the collectionview. But this index can not help me get the same element in the collection _productsPosition, because the

Use UIElements as ItemsSource of ListBox in Silverlight

懵懂的女人 提交于 2019-12-13 03:42:51
问题 I've noticed that if you have anything deriving from UIElement as items in a ListBox in Silverlight it renders the object as is and isn't paying any attention to settings of DisplayMemberPath and/or ListBox.ItemTemplate . For example if you have XAML like this: <ListBox Width="200" Height="300" DisplayMemberPath="Tag"> <TextBlock Tag="tag1">text1</TextBlock> <TextBlock Tag="tag2">text2</TextBlock> <TextBlock Tag="tag3">text3</TextBlock> </ListBox> In Siverlight this produces a ListBox with