datatemplate

is there a datatemplate for grid panel elements in WPF?

扶醉桌前 提交于 2019-11-30 07:34:49
Fairly new to WPF... I have a collection of data I would like to bind to a grid panel. Each object contains its grid row and column, as well as stuff to fill in at the grid location. I really like how I can create data templates in the listbox XAML to create a UI with almost nothing in the code behind for it. Is there a way to create a data template for grid panel elements, and bind the panel to a data collection? You can use an ItemsControl with a Grid as its panel. Here is an example. XAML: <ItemsControl x:Name="myItems"> <ItemsControl.ItemsPanel> <ItemsPanelTemplate> <Grid> <Grid

How to switch between views using DataTemplate + Triggers

孤街醉人 提交于 2019-11-30 05:32:41
I have a requirement where a where user can switch to view hierarchical data either as tree or as a text in datagrid or as FlowChart. The user can do this by clicking a Toggle Button which say: Switch Mode. I want to do all this in such a way that it can be handled within the View only as ViewModel in all the three cases is the same. How do I apply View to my ViewModel based on Trigger. If the state of which view to show is saved in some enum property you could use a ContentControl and DataTriggers for example: <ContentControl> <ContentControl.Style> <Style TargetType="{x:Type ContentControl}"

ContentControl with DataTemplateSelector - help needed

心已入冬 提交于 2019-11-30 05:01:32
问题 I got an enoying problem... Maybe someone can (please!) help. I am using a model that has and enumeration of types and a property that should hold UI models for each selected type from enumeration: Let's define them like: class ViewModel { Types selectedType{get;set;} UiModelBase editedModel{get;set;} } I want to have a content control that use datatemplateselector to change his view each time I change the selectedType. <ListBox x:Name="RuleTypeList" ItemsSource="{Binding Source=

DataTemplate for each DataType in a GridViewColumn CellTemplate

梦想与她 提交于 2019-11-30 04:50:43
I have an ObservableCollection which contains view models of multiple types, and I would like to make a DataTemplate for each type within each of my GridViewColumn's CellTemplates. In this simple example I could create a base ViewModel, but I would like to be able to do this just from xaml. The xaml below shows what I am trying to do, where one of the DataTemplates would be used for each CellTemplate. If there were a GridViewColumn.Resources I would define the DataTemplates there then use a a DataTemplate with ContentPresenter in the CellTemplate, but I obviously can't do that. I'm thinking I

How can I bind an ObservableCollection to TextBoxes in a DataTemplate?

对着背影说爱祢 提交于 2019-11-30 03:49:32
问题 I am trying to successfully TwoWay bind an ObservableCollection to TextBoxes in a DataTemplate. I can get the data to display properly, but I am unable to change the list data through the UI. I have a Model class named 'model' which contains an ObservableCollection named 'List'. The class implements the INotifyPropertyChanged interface. Here is the xaml for the shell. The DataContext for Window1's grid is set to "theGrid.DataContext=model" <Window x:Class="BindThat.Window1" xmlns="http:/

How to Bind To Data within a Datatemplate of a ContentControl

梦想的初衷 提交于 2019-11-30 03:21:30
I have the following simplified Example: <Window x:Class="TemplateBinding.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="MainWindow" Height="350" Width="525"> <Window.Resources> <ResourceDictionary> <ResourceDictionary.MergedDictionaries> <ResourceDictionary Source="pack://application:,,,/TemplateBinding;component/PersonTemplate.xaml" /> </ResourceDictionary.MergedDictionaries> </ResourceDictionary> </Window.Resources> <Grid> <ContentControl ContentTemplate="{StaticResource PersonTemplate}" /> </Grid>

Specifying DataTemplate.DataType with a custom type extension

二次信任 提交于 2019-11-30 03:12:15
问题 I have this markup extension public class NullableExtension : TypeExtension { public NullableExtension() { } public NullableExtension( string type ) : base(type) { } public NullableExtension( Type type ) : base(type) { } public override object ProvideValue( IServiceProvider serviceProvider ) { Type basis = (Type)base.ProvideValue( serviceProvider ); return typeof(Nullable<>).MakeGenericType( basis ); } } which is designed to provide a nullable version of some other type. It works as expected

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

WPF ListBoxItems with DataTemplates - How do I reference the CLR Object bound to ListBoxItem from within the DataTemplate?

£可爱£侵袭症+ 提交于 2019-11-29 18:48:54
问题 I have a ListBox, that's bound to an ObservableCollection . Each ListBoxItem is displayed with a DataTemplate . I have a button in my DataTemplate , that when clicked, needs a reference to the member of the ObservableCollection it's part of the DataTemplate for. I can't use the ListBox.SelectedItem property because the item does not become selected when clicking the button. So either: I need to figure out how to properly set ListBox.SelectedItem when the mouse hovers, or when the button is

Binding to viewmodel from inside a datatemplate

只谈情不闲聊 提交于 2019-11-29 16:21:38
问题 I have multiple videos displayed they are bound with a videocollection in Mainviewmodel. Everything works fine untill I try to bind the enter command to Mainviewmodel. I Don't know the syntax for this. As it stands the binding is set to Video and not Mainviewmodel. Errormessage: 'StartVideoCommand' property not found on 'object' ''Video' Xaml: <Window.Resources> <local:MainViewModel x:Key="MainViewModel"/> </Window.Resources> <Grid DataContext="{StaticResource MainViewModel}"> <ListBox