itemscontrol

DataContext not set when using View as DataTemplate in ItemsControl

被刻印的时光 ゝ 提交于 2019-12-22 10:45:46
问题 I have an ObservableCollection of ViewModels that I'd like to bind to an ItemsControl containing the associated child Views. When I add ViewModels to my collection, an appropriate number of child Views are generated in the ItemsControl. However, the DataContext for each of the generated views is null. If I inline my child view, it works correctly. So, what do I need to do to set the DataContext for my child views to my ViewModels? Here's the relavent bits in my parent ViewModel: public

How to display a “more item” in an ItemsControl when the number of elements is bigger than n?

∥☆過路亽.° 提交于 2019-12-22 09:47:22
问题 I have an ItemsControl that displays tiles in a Windows 8 manner with 2 columns and 4 rows. Each tile is clickable and triggers a command that will load the selected item in another view. My problem starts here: my bound IList<> can contain more than 8 elements at the time, but must display no more than 8 tiles. What I am trying to achieve is to create a different type of tile (linked to another command) that will appear (ex: using a Converter ) only when my IList<> is bigger than 8. Please

WPF GridViewRowPresenter in an ItemsControl

醉酒当歌 提交于 2019-12-22 07:23:09
问题 I'm just starting learning WPF and I'm trying to use a GridViewRowPresenter inside of an ItemsControl to essentially duplicate the functionality of a simple table in HTML. The ListView is not appropriate since it is interactive (which I don't want). I am binding to a generic List of objects of an unknown quantity. I have a List of a custom object that has two string properties: FirstName and LastName. The following code works: <ItemsControl Name="myItemsControl"> <ItemsControl.ItemTemplate>

WPF ItemsControl - how to know when the items finished loading, so that I can focus the first one?

霸气de小男生 提交于 2019-12-21 12:21:27
问题 I have an ItemsControl in my View, that is bound to an ObservableCollection from ViewModel. The collection is filled, and afterwards an event from VM to view is raised (think search results and SearchFinished event). I would like to move keyboard focus to the first item in an ItemsControl, but when I do it in View's code-behind when handling SearchFinished, the items are not yet rendered (the collection is filled already, but wpf's rendering is asynchronous and didn't happen yet), so there is

Should my ViewModel have an ObservableCollection of Views or ViewModels?

。_饼干妹妹 提交于 2019-12-20 12:35:15
问题 I'm trying to understand the basic MVVM design approach when using ItemsControl by binding it via DataTemplates to ObservableCollections on the ViewModel. I've seen examples that bind to ObservableCollections of strings , Views , and ViewModels . Binding to strings seems to be only for demos , it is the binding to " ViewModels that contain collections of Views that contain collections of ViewModels " that the power of WPF seems to really come out. For those of use proficient in the MVVM

creating custom itemscontrol

↘锁芯ラ 提交于 2019-12-20 10:11:26
问题 I'm trying to create a custom control derived from ItemsControl . The ItemsControl is initialized with items, but they are not shown. the itemsControl : public class PipeControl : ItemsControl { static PipeControl() { DefaultStyleKeyProperty.OverrideMetadata(typeof(PipeControl), new FrameworkPropertyMetadata(typeof(PipeControl))); } public PipeControl() { Checkers = new ObservableCollection<Checker>(); Checkers.Add(new Checker()); Checkers.Add(new Checker()); Checkers.Add(new Checker());

Can one bind a combobox Itemssource from a datatemplate of a ItemsControl

限于喜欢 提交于 2019-12-20 05:31:59
问题 Given ComboBox in the ItemsControl will have different items which is based on the DataContext of the item (not of the ItemsControl ). Can it be done? And how? Preferably from code behind. I have the following DataModel : class Tester { public Tester(string name, string surname) { Name = name; Surname = surname; } public string Name { get; set; } public string Surname { get; set; } public override string ToString() { return Name + " " + Surname; } } class TheT { public ObservableCollection

WPF Show data from multiple DataContexts in ToolTip of ItemsControl

不问归期 提交于 2019-12-19 17:42:45
问题 I am trying to display a tooltip for an item generated by an ItemsControl that needs to pull data from conceptually unrelated sources. For example, say I have an Item class as follows: public class Item { public string ItemDescription { get; set; } public string ItemName { get; set; } } I can display the Item within an ItemsControl with a tooltip as follows: <ItemsControl x:Name="itemsControl" ItemsSource="{Binding Items}"> <ItemsControl.ItemTemplate> <DataTemplate> <TextBlock Text="{Binding

WPF Show data from multiple DataContexts in ToolTip of ItemsControl

ぃ、小莉子 提交于 2019-12-19 17:42:15
问题 I am trying to display a tooltip for an item generated by an ItemsControl that needs to pull data from conceptually unrelated sources. For example, say I have an Item class as follows: public class Item { public string ItemDescription { get; set; } public string ItemName { get; set; } } I can display the Item within an ItemsControl with a tooltip as follows: <ItemsControl x:Name="itemsControl" ItemsSource="{Binding Items}"> <ItemsControl.ItemTemplate> <DataTemplate> <TextBlock Text="{Binding

How can I position ViewModels in an ItemsControl

纵然是瞬间 提交于 2019-12-19 11:16:12
问题 My mainwindow ViewModel has an ObservableCollection of ViewModels, called ViewModels. The Mainwindow XAML has an ItemsControl with ItemsSource bound to ViewModels. When I have <ItemsControl ItemsSource="{Binding ViewModels}" /> The Views associated with each ViewModel in the collection are rendered one below the other. The Views are UserControls, displaying dataGrids. How can I position them in a customizable way, for example such that VM1 is on the left, and VM2 and VM3 are stacked one on