datatemplate

How do I use a ItemTemplateSelector together with a HeaderTemplate in a WPF ListView?

≯℡__Kan透↙ 提交于 2019-12-19 05:59:56
问题 Suppose the following XAML defined window: <Window x:Class="LayoutTests.Window1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="clr-namespace:LayoutTests" Title="Window1"> <Window.Resources> <XmlDataProvider x:Key="XmlData" IsInitialLoadEnabled="True"> <x:XData> <Items xmlns=""> <Item text="Item 1" type="A" /> <Item text="Item 2" type="B" /> <Item text="Item 3" type="A" /> </Items> </x:XData> <

Focus on a TextBox in a DataTemplate

ぐ巨炮叔叔 提交于 2019-12-19 05:51:36
问题 I have DataTemplate containing a TextBox . I'm setting this template to a listbox item on a selection. I'm unable to set focus to textbox in the template. I tried to call MyTemplate.FindName, but it ends up with an Invalid Operation Exception: This operation is valid only on elements that have this template applied. How can I access it? 回答1: Since you know the name of the TextBox you want to focus, this becomes relatively easy. The idea is to get hold of the template as it's applied to the

Focus on a TextBox in a DataTemplate

跟風遠走 提交于 2019-12-19 05:51:06
问题 I have DataTemplate containing a TextBox . I'm setting this template to a listbox item on a selection. I'm unable to set focus to textbox in the template. I tried to call MyTemplate.FindName, but it ends up with an Invalid Operation Exception: This operation is valid only on elements that have this template applied. How can I access it? 回答1: Since you know the name of the TextBox you want to focus, this becomes relatively easy. The idea is to get hold of the template as it's applied to the

Implicit DataTemplate doesn't work

浪尽此生 提交于 2019-12-19 05:47:21
问题 Why does the following implicit DataTemplate not work? Only the commented inline DataTemplate will work. Note: If I remove both DataTemplate s, I see a string representation of the ProductListView full type name. <Window.Resources> <DataTemplate DataType="vm:ProductListViewModel"> <v:ProductListView/> </DataTemplate> </Window.Resources> <TabControl ItemsSource="{Binding Tabs}" TabStripPlacement="Left"> <TabControl.ItemTemplate> <DataTemplate> <TextBlock Text="{Binding Key}"/> </DataTemplate>

Implicit DataTemplate doesn't work

孤街醉人 提交于 2019-12-19 05:47:08
问题 Why does the following implicit DataTemplate not work? Only the commented inline DataTemplate will work. Note: If I remove both DataTemplate s, I see a string representation of the ProductListView full type name. <Window.Resources> <DataTemplate DataType="vm:ProductListViewModel"> <v:ProductListView/> </DataTemplate> </Window.Resources> <TabControl ItemsSource="{Binding Tabs}" TabStripPlacement="Left"> <TabControl.ItemTemplate> <DataTemplate> <TextBlock Text="{Binding Key}"/> </DataTemplate>

WPF ListBox - Getting UIElement instead of of SelectedItem

血红的双手。 提交于 2019-12-19 05:13:17
问题 I created a ListBox that has a DataTemplate as Itemtemplate . However, is there an easy way to access the generated UIElement instead of the SelectedItem in codebehind? When I access SelectedItem , I just get the selected object from my ItemsSource collection. Is there a way to access the UIElement (ie. the element generated from the DataTemplate together with the bound object)? 回答1: You are looking for the ItemContainerGenerator property. Each ItemsSource has an ItemContainerGenerator

Are recursive DataTemplates possible?

不问归期 提交于 2019-12-19 05:09:09
问题 I have a class something like: public class Section { private IEnumerable<Section> sections; private IEnumerable<KeyValuePair<string, string>> attributes public string Name {get;set;} public IEnumerable<Section> Sections { get {return sections;} } public IEnumerable<KeyValuePair<string, string>> Attributes { get {return attributes;} } public Section(...) { //constructor logic } } Which is contained in another class, lets call it OtherClass for sake of argument, that wraps around it and is

How do I create a datatemplate with content programmatically?

橙三吉。 提交于 2019-12-18 19:04:52
问题 I want to do the following at runtime in code: <DataTemplate x:Key="lightGreenRectangle"> <Rectangle Fill="LightGreen"/> </DataTemplate> So far I've got: public DataTemplate GetColouredRectangleInDataTemplate(Color colour) { DataTemplate dataTemplate = new dataTemplate(); return dataTemplate; } Help? I know this isn't the most elegant way of styling a control, but the component I want to specify a colour for has a property called "PointTemplate" of type DataTemplate. 回答1: If for whatever

Should I be using UserControls for my Views instead of DataTemplates?

夙愿已清 提交于 2019-12-18 14:54:03
问题 I was reading this post and the author makes the suggestion that using DataTemplates to define a ViewModel is a lunatic's way to do it (#7). I do that all the time, is it really that bad? <DataTemplate DataType="{x:Type local:MyViewModel}"> <Grid> ... </Grid> </DataTemplate> Most of my Views are simply a ResourceDictionary that defines a DataTemplate or two. To me, it makes much better sense to do this than creating a UserControl for every ViewModel. Why would I want the extra layer in WPF's

How to use template binding inside data template in custom control (Silverlight)

时间秒杀一切 提交于 2019-12-18 14:49:32
问题 I am trying to create control which will take ItemsSource and InnerTemplate and will show all the items wrapped in CheckBox es. The control has 2 dependency properties: public static readonly DependencyProperty ItemsSourceProperty = DependencyProperty.Register("ItemsSource", typeof(IEnumerable), typeof(CheckBoxWrapperList), null); public static readonly DependencyProperty InnerTemplateProperty = DependencyProperty.Register("InnerTemplate", typeof(DataTemplate), typeof(CheckBoxWrapperList),