datatemplate

Binding DataGrid Within A DataTemplate of ItemsControl

帅比萌擦擦* 提交于 2019-12-11 09:39:45
问题 I have a strange issue occurring with the binding I'm trying to set up. I have an ItemsControl which I'm using to render a WrapPanel which contains a DataGrid for its DataTemplate. Ultimately I want to use the WrapPanel to show one DataGrid for each item in the list that gets bound to the ItemsControl. Right now it creates the correct number of DataGrids and headers, but there is no data actually being bound. I'm not experienced enough with WPF to know where I'm going astray here. The items

Datatemplate without Listbox/Itemssource

青春壹個敷衍的年華 提交于 2019-12-11 09:13:45
问题 I'm fairly new to WPF, and I'm having a difficulty understanding the subtlety of DataTemplate, DataContext and ofcourse - MVVM. My problem is this: I want to create a DataTemplate for the class Person - which contains a grid which contains three lables - for the First Name, Last Name and Age. After creating my DataTemplate, I wish to add a person to the main grid in the mainwindow, without a listbox or a component which has ItemSource. To sum up my question - I want to know if there's a way

ItemContainerStyleSelector causes binding errors

a 夏天 提交于 2019-12-11 07:57:57
问题 I have two object types, for simplicity I will call them Category and Product. A category may have sub-categories, as well as products. Products do not contain other objects- they are leaves in the tree. public class Product { public string Name {get; set;} } public class Category { public IEnumerable<object> Children { //return a mixed set of categories and products } public bool IsExpanded {get; set;} public bool IsHighlighted {get; set;} } I want to display them in a TreeView, in the exact

Adding Custom Class as TreeViewItem to TreeView WPF

瘦欲@ 提交于 2019-12-11 07:31:43
问题 I have scenario where my TreeView look like below: MainParent .>-Parent ...>--Child1 ...>--Child2 ...>--Child3 ...>--Child4 ...>--Child5 ......> Child1_Of_Child5 ...........>Child1(Child1_Of_Child5) ...........>Child2(Child1_Of_Child5) ......> Child2_of_Child5 ...........>Child1(Child2_Of_Child5) ...........>Child2(Child2_Of_Child5) I am able to bind ObservableCollection till Child1/Child2/../Child5 using HierarchicalDataTemplate. Though I am able to add Child1_Of_Child5 to Child5

How to populate a control inside a DataTemplate whenever the template is instantiated?

烈酒焚心 提交于 2019-12-11 07:17:45
问题 I have an ItemsControl with a DataTemplate describing how to display each item. The UI I'd like to have inside the DataTemplate is a bad fit to be modelled by XAML and I am going to have to populate a Grid in code. How do I get this code to run every time my DataTemplate is instantiated, so that I get a chance to populate the bits I couldn't express in XAML? To expand a little, consider a simplified example. The VM looks like this: class MyItem { public string Name { get; set; } public MyGrid

Can't create content with DataTemplate in code behind with control defined in xaml

血红的双手。 提交于 2019-12-11 06:47:58
问题 I have the following label in a ResourceDictionary in xaml of my ContentPage: <ContentPage.Resources> <ResourceDictionary> <Label Text="I am label" x:Name="label" x:Key="label"/> </ResourceDictionary> </ContentPaget.Resources> And in in my code behind I have this clicked event handler: void Handle_Clicked(object sender, System.EventArgs e) { DataTemplate dataTemplate = new DataTemplate(() => label); for (int i = 0; i < 3; i ++) { Label content = (Label) dataTemplate.CreateContent(); stack

ListBoxItem HorizontalContentAlignment=Stretch not working

左心房为你撑大大i 提交于 2019-12-11 06:46:52
问题 I am having trouble getting my listbox items to stretch to the whole listbox width. Below is my xaml for my listbox <ListBox x:Name="MyListBox" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" HorizontalContentAlignment = "Stretch" Margin="0,10,0,0" ItemsSource="{Binding Path=Users}" ScrollViewer.HorizontalScrollBarVisibility="Disabled" Grid.Column="0" Grid.ColumnSpan="1" Grid.Row="1" Grid.RowSpan="3"> <ListBox.ItemTemplate> <DataTemplate> <local:MyListBoxTemplate/> </DataTemplate> <

WPF - Get DataTemplate without an event

南楼画角 提交于 2019-12-11 06:33:58
问题 I have a WPF Data template defined in my Windows.Resources section. I would like to access this (really a list box on it) via the code behind. How can I do this? I can't get what I want via an event because I want to get the reference in the completed step of a BackGroundWorker. (Ie no sender (that is a UI element) to go off of there). How can I get a reference to this? I have tried: myContainingPanel.Template.Find("lstBox", myContainingPanel); and (Taken from here): ContentPresenter

Getting at the “parent” of a databound object?

泪湿孤枕 提交于 2019-12-11 06:29:09
问题 I have an object with two arrays of strings. The object is data bound to a listbox. One list is bound as the list's ItemsSource. The other, which is the thing causing me trouble, needs to be bound to a combobox that's part of a DataTemplate that is set to the list's ItemTemplate. Basically each item on the listbox has the corresponding element of the first list and a combo box that contains the second list. In other words, every item in the list has the same combobox of choices. The problem

Why SelectionChanged is called when view is unloaded?

牧云@^-^@ 提交于 2019-12-11 05:55:42
问题 Below is an mcve (to reproduce the problem it has to be datatemplated unloadable view). xaml: <Window Content="{Binding}" ... > <Window.Resources> <DataTemplate DataType="{x:Type local:ViewModel}"> <ListView ItemsSource="{Binding Items}" SelectionChanged="ListView_SelectionChanged" Unloaded="ListView_Unloaded" MouseRightButtonDown="ListView_MouseRightButtonDown"> </ListView> </DataTemplate> </Window.Resources> </Window> cs: public class ViewModel { public ObservableCollection<string> Items {