datatemplate

Problem with SelectedItem of WPF Editable ComboBox with DataTemplate

匆匆过客 提交于 2019-12-04 12:45:38
I’m having the following issue with WPF ComboBox : XAML: <Window.Resources> <ResourceDictionary> <DataTemplate DataType="{x:Type this:Data}"> <ComboBox IsTextSearchEnabled="False" IsEditable="True" Text="{Binding Value}" ItemsSource="{Binding Menu}"/> </DataTemplate> </ResourceDictionary> </Window.Resources> <StackPanel> <ContentControl Content="{Binding}"/> <Button Click="ChangeData_Click">Change Data</Button> </StackPanel> Code behind: public Window1() { InitializeComponent(); DataContext = new Data(); } void ChangeData_Click(object sender, RoutedEventArgs e) { DataContext = new Data(); } I

Contentpresenter with type based datatemplate selection and binding

拈花ヽ惹草 提交于 2019-12-04 10:51:11
I have an ItemsControl that binds to a list of items. These items have a name and value property. The value property is of type Object to allow different datatypes to be used. To display the value property correctly I use a ContentPresenter with a datatemplate for every datatype I might use. <ItemsControl ItemsSource="{Binding Items}"> <ItemsControl.ItemTemplate> <DataTemplate> <Grid> <Grid.ColumnDefinitions> <ColumnDefinition Width="*"/> <ColumnDefinition Width="Auto" /> <ColumnDefinition Width="*"/> </Grid.ColumnDefinitions> <TextBlock Text="{Binding Path=Name}"/> <GridSplitter Width="1"

Is it possible to bind an Event in a Silverlight DataTemplate?

自作多情 提交于 2019-12-04 10:27:38
问题 Is it possible to bind an Event in a Silverlight DataTemplate? If so, what is the best way to do it? For example, say you've created a DataTemplate that has a Button in it, like this: <UserControl.Resources> <DataTemplate x:Key="MyDataTemplate" > <Grid> <Button Content="{Binding ButtonText}" Margin="4" /> </Grid> </DataTemplate> </UserControl.Resources> Then, you apply it to a ListBox ItemTemplate, like this: <Grid x:Name="LayoutRoot" Background="White"> <ListBox x:Name="lbListBox"

Adding Visual States to a Data Template in Windows 8

▼魔方 西西 提交于 2019-12-04 09:57:10
I am trying to add a Mouse Over effect to my Windows 8 application. Specifically I'm trying to add it to DataTemplates bound to a GridView. However, Currently, nothing is happening, I've tried to follow the Microsoft tutorials but most of those are either out of date or for different versions of XAML. My code looks like this: <DataTemplate x:Key="GameTileTemplate"> <Grid x:Name="grid" Width="173" Height="173" RenderTransformOrigin="0.5,0.5" > <Grid.Clip> <RectangleGeometry Rect="0,0,173,173"/> </Grid.Clip> <Image Grid.RowSpan="3" Stretch="UniformToFill"/> <Grid x:Name="DataPanel" Margin="-173

Change TreeViewItem Template when IsSelected and two types using in TreeView

痴心易碎 提交于 2019-12-04 09:41:27
In my TreeView I use two differnt classes for binding. For example, I have a Group what can have ChildGroup and can have Items. Example code of this classes: using System.Collections.Generic; using System.Collections.ObjectModel; namespace WpfApplication1 { public class Group { public Group(string name) { Name = name; items = new ObservableCollection<Item>(); groups = new ObservableCollection<Group>(); } public string Name { get; set; } private ObservableCollection<Item> items; private ObservableCollection<Group> groups; public ObservableCollection<Item> Items { get { return items; } } public

Dynamically added DataTemplate - StaticResource for Converter can't be found

时光毁灭记忆、已成空白 提交于 2019-12-04 09:23:10
问题 I'm using the following code to dynamically add columns to my GridView: public void AddGridViewColumns() { GridView view = (GridView)_myListView.View; GridViewColumn column = BuildGridViewColumn(1); view.Columns.Add(column); } public virtual GridViewColumn BuildGridViewColumn(int blockIndex) { string templateXaml = string.Format( @"<DataTemplate xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation"" xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml"" xmlns:local=""clr

Add data-binding for DataGridTemplateColumn created in code

左心房为你撑大大i 提交于 2019-12-04 09:15:22
The question: Is there a way to define a DataTemplate in XAML and instantiate it in code (rather than retrieve singleton by FindResource ) and modify its VisualTree before sending to where a DataTemplate is required such as DataGridTemplateColumn.CellTemplate ? Background: I am displaying a 2-dimensional array data[][] in a DataGrid by adding DataGridTemplateColumn columns on my own and there is a DataTemplate defined in XAML that knows how to present each element in the array. However the default DataContext for each cell is the row, i.e. data[x] . So I need to "parameterize" the DataTemplate

How to set the DataContext for a View created in DataTemplate from ViewModel

霸气de小男生 提交于 2019-12-04 09:02:05
There are questions on this already, but they don't answer my question. For example: <ContentControl.Resources> <DataTemplate DataType="{x:Type Databinding:RedScreenViewModel}" > <Databinding:RedScreen DataContext="{Binding}"/> </DataTemplate> <DataTemplate DataType="{x:Type Databinding:BlueScreenViewModel}"> <Databinding:BlueScreen DataContext="{Binding}" /> </DataTemplate> </ContentControl.Resources> As you can see I am attempting to set the DataContext for the created View hoping that it would use the ViewModel that was used to create it. But when I step through the code behind.. the

'Default' text for templated combo box

一笑奈何 提交于 2019-12-04 07:07:55
I have a combo box that is based on a data template the includes check boxes like such: <ComboBox x:Name="cboComplex" Text="Select days..."> <ComboBox.ItemTemplate> <DataTemplate> <StackPanel Orientation="Horizontal"> <CheckBox IsChecked="{Binding Path=IsSelected}" Width="20"/> <TextBlock Text="{Binding DayOfWeek}" Width="100" /> </StackPanel> </DataTemplate> </ComboBox.ItemTemplate> </ComboBox> The problem I'm having is that I'd like the combobox to display "Select days..." and then show the list when clicked. Unfortunately setting the Text property seems to have no effect. Any ideas or help

GridViewColumn CellTemplate Code Behind

╄→гoц情女王★ 提交于 2019-12-04 07:07:10
I have a listView that I construct at run-time, i.e. the columns are not known at compile-time. I would like to apply a DataTemplate to the cells such that the TextAlignment property is TextAlignment.Right. When creating the columns: foreach (var col in dataMatrix.Columns) { gridView.Columns.Add( new GridViewColumn { Header = col.Name, DisplayMemberBinding = new Binding(string.Format("[{0}]", count)), CellTemplate = getDataTemplate(count), }); count++; } private static DataTemplate getDataTemplate(int count) { DataTemplate template = new DataTemplate(); FrameworkElementFactory factory = new