contenttemplateselector

ContentControl.ContentTemplateSelector dynamically select template

倖福魔咒の 提交于 2019-12-22 04:48:18
问题 I set a ContentControl in the right of Window, and set Content binding Items (it's type is ObservableCollection). Now I want to achieve it: if there are no item, ContentControl select first DataTemplate, and add a item into items, ContentControl will select second DataTemplate to display some info. Like this: The problem is when I add one item into items, ContentControl didnot update and change DataTemplate, I have a try to set mode, UpdateSourceTrigger, etc., but failed. In ViewModel, after

Why is the SelectTemplate Method run 2 times in debug mode?

假装没事ソ 提交于 2019-12-12 01:43:48
问题 debuging this class the SelectTemplate Method is run 2 times, but why? The first time the item is always null. public class PersonDataTemplateSelector : DataTemplateSelector { public override DataTemplate SelectTemplate(object item,DependencyObject container) { if (item is Person) { Person person = item as Person; Window window = Application.Current.MainWindow; if (System.ComponentModel.DesignerProperties.GetIsInDesignMode( window)) return null; if (person.Gender == "male") return window

ContentControl.ContentTemplateSelector dynamically select template

半腔热情 提交于 2019-12-05 04:42:28
I set a ContentControl in the right of Window, and set Content binding Items (it's type is ObservableCollection). Now I want to achieve it: if there are no item, ContentControl select first DataTemplate, and add a item into items, ContentControl will select second DataTemplate to display some info. Like this: The problem is when I add one item into items, ContentControl didnot update and change DataTemplate, I have a try to set mode, UpdateSourceTrigger, etc., but failed. In ViewModel, after delete a item, I use this statements, it will work well <1> : private void ExecuteDeleteClientCommand()

Changing ContentTemplate based on ListBox selection

六月ゝ 毕业季﹏ 提交于 2019-12-04 13:36:28
问题 I have a Listbox and a Border in a StackPanel similar to the following: <StackPanel Orientation="Horizontal"> <ListBox> <ListBoxItem Content="People"/> <ListBoxItem Content="Animals"/> <ListBoxItem Content="Cars"/> </ListBox> <Border Width="200> <ContentPresenter/> </Border> </StackPanel> When selecting an item in the listbox I would like to change the content in the ContentPresenter accordingly e.g. selecting People would change the template to display a series of input fields related to

ContentTemplateSelector is only called one time showing always the same datatemplate

拈花ヽ惹草 提交于 2019-11-30 13:58:49
I have made a sample demo VS 2010 RC sample project, because in my production project I have the same error using MVVM. In my sample demo project I use only Code-behind without 3rd party dependencies so you can download the demo project here and run it for yourself: http://www.sendspace.com/file/mwx7wv Now to the problem: When I click the girls/boys button it should switch the datatemplate, not? What do I wrong? OK I offer here a code snippet too: Code-Behind MainWindow.cs : namespace ContentTemplateSelectorDemo { /// <summary> /// Interaction logic for MainWindow.xaml /// </summary> public

ContentTemplateSelector is only called one time showing always the same datatemplate

孤人 提交于 2019-11-29 19:28:11
问题 I have made a sample demo VS 2010 RC sample project, because in my production project I have the same error using MVVM. In my sample demo project I use only Code-behind without 3rd party dependencies so you can download the demo project here and run it for yourself: http://www.sendspace.com/file/mwx7wv Now to the problem: When I click the girls/boys button it should switch the datatemplate, not? What do I wrong? OK I offer here a code snippet too: Code-Behind MainWindow.cs : namespace

Why would 'this.ContentTemplate.FindName' throw an InvalidOperationException on its own template?

丶灬走出姿态 提交于 2019-11-28 09:10:35
Ok... this has me stumped. I've overridden OnContentTemplateChanged in my UserControl. I'm checking that the value passed in for newContentTemplate does in fact equal this.ContentTemplate (it does) yet when I call this... var textBox = this.ContentTemplate.FindName("EditTextBox", this); ...it throws the following exception... "This operation is valid only on elements that have this template applied." Per a commenter in another related question, he said you're supposed to pass in the content presenter for the control, not the control itself, so I then tried this... var cp = FindVisualChild

Why would 'this.ContentTemplate.FindName' throw an InvalidOperationException on its own template?

白昼怎懂夜的黑 提交于 2019-11-27 02:44:56
问题 Ok... this has me stumped. I've overridden OnContentTemplateChanged in my UserControl. I'm checking that the value passed in for newContentTemplate does in fact equal this.ContentTemplate (it does) yet when I call this... var textBox = this.ContentTemplate.FindName("EditTextBox", this); ...it throws the following exception... "This operation is valid only on elements that have this template applied." Per a commenter in another related question, he said you're supposed to pass in the content