datatemplate

Need help handling events of a DataTemplate in the Application.xaml file

萝らか妹 提交于 2020-01-04 05:16:09
问题 I have in my application a data template that has a few buttons. I want those buttons' even handler to be fired in the current page (I am using this template in many pages) rather than in the Application.xaml.vb/cs file, since I want different actions on each page. I hope I am clear. 回答1: You can use commanding to achieve this. Have the Button s in the DataTemplate execute specific Command s: <Button Command="{x:Static MyCommands.SomeCommand}"/> Then have each view that uses that DataTemplate

WPF context menu whose items are defined as data templates

怎甘沉沦 提交于 2020-01-04 04:37:13
问题 I have a list view that displays a collection of items, each item has as its underlying data a view model (MVVM). What I would like to do is display different menu items within the context menu when the user right clicks one of these list view items. The menu items displayed is dependent on the type of the item selected (i.e. the type of the underlying view model). I would expect the below to work, but it does not (no items are displayed in the context menu). <ListView.ContextMenu>

uwp should I be using user control inside a data template?

拈花ヽ惹草 提交于 2020-01-03 17:51:06
问题 in my UWP app I was thinking to extract my data template into a seperate user control , i.e: <DataTemplate><local:CustomTemplate/></DataTemplate> and the user control ( customtemplate ) will have that stackpanel or grid which was previously in my DataTemplate directly, along with its bindings, I already know how to achieve this. My Question is that by extracting out the data template in a user control, would this cause any performance hit? I read somewhere that while doing this each

Programmatically set content in Silverlight DataGrid details

a 夏天 提交于 2020-01-03 03:45:13
问题 I need to dynamically set the contents within the template of a DataGrid based on information in an external settings file. That settings file specifies which data fields should display in the DataGrid. The administrator of the application can edit the settings to change the fields to display. I cannot hard-code the fields to display. I can easily add the columns (DataGridTextColumn's) to the DataGrid at runtime. I set a binding to a field in the item source based on the settings, and that

DataTemplate for a DataType - how to override this DataTemplate in a particular ListBox?

荒凉一梦 提交于 2020-01-02 06:58:31
问题 I have created several DataTemplates for some of the DataTypes in my pet project. These data templates are really cool as they work like magic, magically transforming the look of the instances of the data types whenever and wherever they show up in the UI. Now I want to be able to change the DataTemplate for these DataTypes in one particular ListBox. Does this mean I have to stop relying on WPF automatically applying the data template to the data types and assign a x:Key to the DataTemplates

Outside Property inside a DataTemplate WPF

落爺英雄遲暮 提交于 2020-01-02 05:36:05
问题 Scenario: I have a ListBox and the ListBoxItems have a DataTemplate. What I want to do is put a ContextMenu in the DataTemplate. The catch is that I want this ContextMenu ItemsSource to be different depending on certain properties in the window. My initial thought is that I could just bind the ItemsSource to a Property in the window and that would return an ItemsSource; however, I cant seem to bind to this property correctly. I believe this is because I am in the DataTemplate and consequently

Design time data for datatemplate in xaml

北城以北 提交于 2020-01-02 00:59:07
问题 This may be a stupid question, but is it possible to define some sample data as DataContext in order to see my DataTemplate in DesignView? At the moment I always have to run my application to see whether my changes are working. E.g. with the following code DesignView just shows an empty list box: <ListBox x:Name="standardLayoutListBox" ItemsSource="{Binding myListboxItems}"> <ListBox.ItemTemplate> <DataTemplate> <Grid> <Grid.RowDefinitions> <RowDefinition /> <RowDefinition /> </Grid

Attaching an Event Handler to a Code Generated DataTemplate

谁都会走 提交于 2020-01-01 06:06:34
问题 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=""

Unable to set ContentTemplate via DataTrigger

自古美人都是妖i 提交于 2020-01-01 05:18:10
问题 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

dynamic datatemplate with valueconverter

99封情书 提交于 2019-12-31 04:41:06
问题 I want to show data in a wpftoolkit datagrid where the data is a collection of public class Thing { public string Foo { get; set; } public string Bar { get; set; } public List<Candidate> Candidates { get; set; } } public class Candidate { public string Name { get; set; } public CandidateType CandidateType { get; set; } } public enum CandidateType { Type1, Type2, Type42 } where the number of candidates in Candidates list is configurable at runtime. Desired grid layout looks like this Foo | Bar