datatemplate

How to define a DataTemplate in code?

无人久伴 提交于 2019-12-03 23:38:36
How can I create a DataTemplate in code (using C#) and then add a control to that DataTemplate ? <data:DataGrid.RowDetailsTemplate> <DataTemplate> <Border> <Border Margin="10" Padding="10" BorderBrush="SteelBlue" BorderThickness="3" CornerRadius="5"> <TextBlock Text="{Binding Description}" TextWrapping="Wrap" FontSize="10"> </TextBlock> </Border> </Border> </DataTemplate> </data:DataGrid.RowDetailsTemplate> I am using Sivlerlight. Josh As far as I know, the only way to create a DataTemplate in Silverlight is to use XamlReader . Basically you would just pass it the XAML as a string and it will

Generic DataTemplate used in multiple GridViewColumns

穿精又带淫゛_ 提交于 2019-12-03 21:14:03
问题 I have a GridView that displays some values: <ListView ItemsSource="{Binding MyDataSource}"> <ListView.View> <GridView> <GridViewColumn Header="Date1" DisplayMemberBinding="{Binding Date1}" /> <GridViewColumn Header="Date2" DisplayMemberBinding="{Binding Date2}" /> ...other Columns, not necessarily containing dates... </GridView> </ListView.View> </ListView> This works fine. Now I want to create a data template that formats a date in a specific way: <DataTemplate x:Key="MySpecialDate">

How do you use a DataType-targeted DataTemplate together with GridView?

有些话、适合烂在心里 提交于 2019-12-03 20:34:41
Before you answer: This question is about WPF's ListView control (with GridView ). It is not about WPF's DataGrid control, ASP.NET's DataGrid or ListView controls, or WinForm's DataGridView or ListView controls. They all sound very similar and are often confused, but an answer for the wrong type of control is both unhelpful to me and more importantly a waste of the time you took to write the answer, which I believe should not be squandered. I have a ListView control with GridView that has several columns bound to my view-model's properties. I can easily customize the visual appearance of the

WPF Memory Usage

女生的网名这么多〃 提交于 2019-12-03 17:49:58
问题 Application: WPF Application consisting of a textbox on top and a listbox below Users type a string in the TextBox to find employees, and search results are displayed in the ListBox ListBox uses DataTemplates to display elements (shows employee name, department, phone and a thumbnail picture.) Implementation: At application startup I query the database and retrieve all employees and related information to be shown in the ListBox. This is kept in memory the entire time. After application

Attaching an Event Handler to a Code Generated DataTemplate

心已入冬 提交于 2019-12-03 17:24:40
I have a question related to this one : I'm trying to attach an event to my StackPanel but it doesn't appear to connect when using the XamlReader. I can't get the ChildItem_Load method to get called. Does anyone know of a way to do this? Other than this event the code works fine. this._listBox.ItemTemplate = (DataTemplate) XamlReader.Load( @"<DataTemplate xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation""> <Border> <StackPanel Loaded=""ChildItem_Loaded""> <TextBlock Text=""{Binding " + this._displayMemberPath + @"}"" /> </StackPanel> </Border> </DataTemplate>" Ok, I figured

Name does not exist in the namespace

我只是一个虾纸丫 提交于 2019-12-03 15:16:04
I am working on a simple UWP project using data template binding in VS 2015. When ever I try to specify the type for the Datatemplate I get an error. XAML: <Page x:Name="RootPage" x:Class="Adaptive_News_Layout.MainPage" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="using:Adaptive_News_Layout" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" FontSize="22" > <SplitView x:Name="MySplitView" Grid.Row="1"

DataTemplates in WPF

拥有回忆 提交于 2019-12-03 14:48:13
I have a general question about data templates in WPF. Let's say I have an abstract class called "Question," and various subclasses like "MathQuestion," "GeographyQuestion," etc. In some contexts, rendering the questions as a "Question" using the "Question" data template is good enough, but let's say that I have a list of random Question objects of varying subclasses that I want to display in-turn. I want to display them to the user using their specific data templates rather than their generic Question data template, but since I don't know that at design time, is there anyway to tell WPF, "hey

DataTemplate vs ItemContainerStyle

僤鯓⒐⒋嵵緔 提交于 2019-12-03 13:43:14
I've seen a few other Silverlight 'vs' questions around, but couldn't find any for this particular match-up. I'm trying to define the way in which my objects bound to a ListBox will display. I've defined a DataTemplate , but I'm really not sure where this should end and the ItemContainerStyle should begin. Question 1: Is the ItemContainerStyle just a wrapper for the DataTemplate so that a common item style can be applied to different data layouts? Question 1a: If so, in the event that a common item style isn't required, is the ItemContainerStyle even necessary or can all the layout and styling

Unable to set ContentTemplate via DataTrigger

荒凉一梦 提交于 2019-12-03 13:33:51
I want the ContentTemplate to vary according to the value in the DataTrigger . And yes, I considered using a DataTemplateSelector , but now I need a DataTrigger or better said a MultiDataTrigger . Please take a look at the following sample app, the DataTemplate doesn't change: <Window x:Class="Window1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:src="clr-namespace:WpfApplication1"> <StackPanel> <CheckBox IsChecked="{Binding BoolProperty, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type src

Distinct item template for first and last item in a ListView

浪尽此生 提交于 2019-12-03 12:53:16
I need to style the first and last items of a list view differently. To achieve that, I started working on a solution based on that answer: Use different template for last item in a WPF itemscontrol Basically, I have a custom ItemsTemplateSelector that decide on the template to apply based on the item's index in the list view items (code below). It works properly except that when the list gets updated (an item is added or removed), the templates do not get selected again (for instance, initially, the SingleItemTemplate gets selected because there is a single item. When I add an item to the