itemssource

Need SIMPLE working example of setting WPF MVVM ComboBox ItemsSource based on SelectedValue of second ComboBox

十年热恋 提交于 2019-12-01 04:39:56
问题 Can anyone show me a simple working example for a WPF MVVM application to set the ItemsSource of combobox B based on the SelectedItem of ComboBox A? It seems from what I've found on this site that it gets all too complicated all too quickly. What's the "right" MVVM way to get it done? Thank you. EDIT I updated using Didier's example. An extract of my XAML: <ComboBox Name="BrowserStackDesktopOS" ItemsSource="Binding Platforms.AvailableBrowserStackDesktopOSes}" SelectedIndex="0" SelectedItem="

GridView column width does not update when changing ItemsSource

早过忘川 提交于 2019-12-01 01:30:30
I have a GridView where I'm setting the ItemsSource in code-behind. All columns in the grid are defined in XAML, and all column widths are "Auto". When I initially set ItemsSource of the grid, the column widths are set correctly. Now, depending on the user's actions, the ItemsSource of the grid may be set to a new EntityCollection. What I have noticed is that the column widths remain as they were with the previous ItemsSource. That is, the column widths don't seem to adjust themselves automatically when a new ItemsSource is set for the Grid. Is there any way in code-behind or XAML to force the

Binding to DataContext outside current ItemsSource context

老子叫甜甜 提交于 2019-11-30 19:18:33
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 outside the DataGrid. The Grid's ItemsSource changes the data context and I don't know how to refer outside

WPF: Two DataGrids, same ItemsSource, One IsReadOnly, Bug?

耗尽温柔 提交于 2019-11-30 16:23:32
I have a WPF application with two DataGrids that share the same ItemsSource. When I set one of the DataGrid's IsReadOnly property to true, I lose the ability to add records to the other DataGrid. I can still edit the contents of the second datagrid, but just cannot add records. Is this intended? Is there way around this? I could use IsEnabled="False" for the DataGrid, but I then lose the ability to scroll in it. Here is the setup: XAML: <Grid> <Grid.RowDefinitions> <RowDefinition Height="*" /> <RowDefinition Height="*" /> </Grid.RowDefinitions> <DataGrid Name="dgA" Grid.Row="0"

IsSynchronizedWithCurrentItem attribute and current item updates

为君一笑 提交于 2019-11-30 12:46:05
I have a view model to manage a dialog type of view that allows filtering of a listing (if necessary) and selection of an item. The code works fine whether I set IsSynchronizedWithCurrentItem to true or not. My understanding is that this property is not true by default in a ListView, so I'd like to better understand this property. Here is the binding setup in the view's xaml (which works just as well without the synch property setting): <ListView ItemsSource="{Binding Projects.View}" IsSynchronizedWithCurrentItem="True" SelectedItem="{Binding SelectedProject, Mode=TwoWay}" > The view model

Custom ItemsSource property for a UserControl

橙三吉。 提交于 2019-11-30 11:03:54
问题 Does anyone know how to make a custom ItemsSource ? What I want to do is to make an itemsSource to my own UserControl so that it could be bound by ObservableCollection<> . Also, I could know Whenever the number of items in the itemsSource updated, so as to do further procedures. Thank you so much. 回答1: You may need to do something like this in your control public IEnumerable ItemsSource { get { return (IEnumerable)GetValue(ItemsSourceProperty); } set { SetValue(ItemsSourceProperty, value); }

ItemsControl.ItemsSource MVVM performance

≯℡__Kan透↙ 提交于 2019-11-30 05:27:04
I have an (non-virtualized) ItemsControl that binds its ItemsSource to a ObeservableCollection of ViewModel instances. Now once the large amount Model instances is loaded all the ViewModel complemnents needs to be added to that ObservableCollection. How can I add a large amount of ViewModels without making the UI Thread hang? I suppose the UI Thread hangs because each time a new item is added the ItemsControl needs to update itself and does layout etc. over and over again. Should I suspend the binding add all items and then resume? If so, how? Should I override the ObservableCollection to

Custom ItemsSource property for a UserControl

纵然是瞬间 提交于 2019-11-29 23:34:52
Does anyone know how to make a custom ItemsSource ? What I want to do is to make an itemsSource to my own UserControl so that it could be bound by ObservableCollection<> . Also, I could know Whenever the number of items in the itemsSource updated, so as to do further procedures. Thank you so much. You may need to do something like this in your control public IEnumerable ItemsSource { get { return (IEnumerable)GetValue(ItemsSourceProperty); } set { SetValue(ItemsSourceProperty, value); } } public static readonly DependencyProperty ItemsSourceProperty = DependencyProperty.Register("ItemsSource",

WPF: Two DataGrids, same ItemsSource, One IsReadOnly, Bug?

淺唱寂寞╮ 提交于 2019-11-29 23:08:13
问题 I have a WPF application with two DataGrids that share the same ItemsSource. When I set one of the DataGrid's IsReadOnly property to true, I lose the ability to add records to the other DataGrid. I can still edit the contents of the second datagrid, but just cannot add records. Is this intended? Is there way around this? I could use IsEnabled="False" for the DataGrid, but I then lose the ability to scroll in it. Here is the setup: XAML: <Grid> <Grid.RowDefinitions> <RowDefinition Height="*" /

IsSynchronizedWithCurrentItem attribute and current item updates

倖福魔咒の 提交于 2019-11-29 18:54:33
问题 I have a view model to manage a dialog type of view that allows filtering of a listing (if necessary) and selection of an item. The code works fine whether I set IsSynchronizedWithCurrentItem to true or not. My understanding is that this property is not true by default in a ListView, so I'd like to better understand this property. Here is the binding setup in the view's xaml (which works just as well without the synch property setting): <ListView ItemsSource="{Binding Projects.View}"