datatemplate

Access Element inside Silverlight DataTemplate

北慕城南 提交于 2019-12-10 05:05:38
问题 I have not been able to find a clean solution to the following problem even though there are a few related questions already on SO. If I have a data template that is being used multiple times, for example, a TreeViewItem.HeaderTemplate, how can I change something the template for only some of the TreeViewItems. For example, let's say my TVI HeaderTemplate has a textblock and depending on the string, I want to make the fontweight bold. I want to do something like this: ((TextBlock)myTreeView

ListView: define ItemsPanelTemplate in resource dictionary

折月煮酒 提交于 2019-12-10 03:30:40
问题 I have a ListView which layout looks like a Windows Explorer view (icon + some details), bound to a list somewhere in the ViewModel. My aim here is to be able to switch between explorer view or classic view whenever we want. I could define an ItemsPanelTemplate doing exactly the work to display correctly the layout, directly in the ListView.ItemsPanel field. Now, I'd like to define it in the resources so that I'll be able to use it in different views, and especially in one control, the user

Why is this WPF ComboBox not showing the selected value?

雨燕双飞 提交于 2019-12-09 23:41:43
问题 <CombobBox x:Name="cbo" Style="{StaticResource ComboStyle1}" DisplayMemberPath="NAME" SelectedItem="{Binding Path=NAME}" SelectedIndex="1"> <ComboBox.ItemTemplate> <DataTemplate> <Grid> <TextBlock Text="{Binding Path=NAME}"/> </Grid> </DataTemplate> </ComboBox.ItemTemplate> </ComboBox> In the Window OnLoaded event, I wrote the code to set the ItemsSource : cbo.ItemsSource = ser.GetCity().DefaultView; While loading the window I can see that the initially the the first item is loading but at

DataTemplate vs ItemContainerStyle

谁说我不能喝 提交于 2019-12-09 10:53:25
问题 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

How to bind from a ContentTemplate to the surrounding custom Control?

别等时光非礼了梦想. 提交于 2019-12-08 20:01:48
问题 I've got the following user control: <TabItem x:Name="Self" x:Class="App.MyTabItem" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:app="clr-namespace:App" > <TabItem.Header> <!-- This works --> <TextBlock Text="{Binding ElementName=Self, Path=ShortLabel, UpdateSourceTrigger=PropertyChanged}"/> </TabItem.Header> <TabItem.ContentTemplate> <DataTemplate> <!-- This binds to "Self" in the surrounding window's namespace

WPF ListBox bind to index of the item

▼魔方 西西 提交于 2019-12-08 18:03:27
问题 It's easy to bind something to the SelectedIndex of the ListBox, but I want every item in the ListBox be able to bind to it's index in the list. Might sound weird, so here's what I'm trying to do: <DataTemplate x:Key="ScenarioItemTemplate"> <Border Margin="8,2,8,2" Background="#FF3C3B3B" BorderBrush="#FF797878" BorderThickness="2" CornerRadius="5"> <DockPanel> <DockPanel DockPanel.Dock="Top" Margin="0,2,0,0"> <Label HorizontalAlignment="Left" DockPanel.Dock="Left" FontWeight="Heavy"

Can a DataTemplate be tied to a nested class?

纵饮孤独 提交于 2019-12-08 16:43:59
问题 Can a DataTemplate in XAML be associated with a nested class? I am working on a MVVM application, and I have run into a data template problem. I have a view model providing a collection of other view models for an items control. These items are part of a hierarchy defined as nested classes in the outer view model. I have been unable so far to create a mapping in XAML to reference the inner nested class. Here is the class hierarchy (simplified for brevity): public class MainViewModel { public

Using a resource and DataTemplateSelector from a different assembly

微笑、不失礼 提交于 2019-12-08 13:05:43
问题 I have a control in a base assembly with Content that I would like to set based on the current DataContext. To do so, I am trying to use a resource and subclassed DataTemplateSelector in the calling assembly as shown below. My initial hope was that the sub classed DataTemplateSelector would be called, but it isn't. Then I tried adding an entry in the Resource Dictionary of the calling assembly with the same key but the sub classed selector, but that doesn't get it done either. Is there a way

WPF HierarchicalDataTemplate treeview

非 Y 不嫁゛ 提交于 2019-12-08 12:22:39
问题 I have some objects I would like to display using a TreeView . The classes I use are defined like this: public abstract class QueryPart { private static Random _random; protected static Random Random { get { return _random??(_random=new Random(654)); } } public string Name { get; set; } public QueryPart() { this.Name = this.GetType().Name + " " + Random.Next(); } } public abstract class Criterium : QueryPart { object ParamValue { get; set; } protected Criterium() { ParamValue = Random.Next();

Accessing an ItemsControl item as it is added

久未见 提交于 2019-12-08 11:45:08
问题 In a previous post, I was advised to use a DataTemplate to render a group of Buttons and Labels, and it works wonderfully. The problem is that I have several of these groups of Buttons, and I would like to distinguish one group from another. I plan to use the AlternatingIndex to color each group differently, but that's not enough -- each group actually needs to have its index printed as well. Here's a contrived example... let's say the Item looks something like this: Lock Door Safe Unlock