datatemplate

WPF - Making an animation's execution conditional on a property of the bound data item

一笑奈何 提交于 2019-11-29 06:46:35
问题 I have a data object -- a custom class called Notification -- that exposes a IsCritical property. The idea being that if a notification will expire, it has a period of validity and the user's attention should be drawn towards it. Imagine a scenario with this test data: _source = new[] { new Notification { Text = "Just thought you should know" }, new Notification { Text = "Quick, run!", IsCritical = true }, }; The second item should appear in the ItemsControl with a pulsing background. Here's

How to bind DataTemplate datatype to interface?

不问归期 提交于 2019-11-29 05:27:33
I am writing a composite loosely coupled MVVM WPF application and child VMs in a parent VM are interfaces rather than class instances, e.g. public IChildViewModel { get; set; } Now how do I render this property using a DataTemplate? like: <DataTemplate DataType="{x:Type contracts:IChildViewModel}"> I understand due to the nature of interfaces (multiple inheritance etc.) WPF does not allow this direct binding. But as interfaces should be used widely in loosely coupled applications, is there any workaround to bind DataTemplate to interfaces? Thanks. You can bind to interfaces by telling wpf

Always show FooterTemplate, even no data

末鹿安然 提交于 2019-11-29 04:41:56
Is there a short way to make a FooterTemplate (in a GridView) always visible, even when DataSource is empty? If you want it to always display, regardless of content, can't you just put the footer html outside the GridView , instead of in the FooterTemplate ? If that's not an option for some reason, then you can either add an null row to your data source if it's empty , or subclass the GridView & override the default behaviour . Those are the only options I'm aware of (although its been a while since the last time I used a GridView ). Aximili I was having trouble with this as well. The link

How to switch between views using DataTemplate + Triggers

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-29 04:17:02
问题 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. 回答1: If the state of which view to show is saved in some enum property you could use a ContentControl and

WPF: How to bind to only one item in a collection, not using ItemsControl since I don't want to display all of them

霸气de小男生 提交于 2019-11-29 03:34:41
I have this requirement, that I have a collection of items (ObservableCollection), but I only want to display the first item. The requirement comes from the fact that in most of the case, the collection only contains one item. And due to the space limit, even if there is more than one items in the collection, we'd like to display the number of the items, details of the first one (same presentation as prior situation) and a ... symbol to indicate to the user that there is more items. And when the mouse is over the UI element a popup will eventually display all items. The first solution I can

DataTemplate for each DataType in a GridViewColumn CellTemplate

霸气de小男生 提交于 2019-11-29 02:18:45
问题 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

Event handler in DataTemplate

前提是你 提交于 2019-11-29 02:08:37
I have WPF ComboBox inside a data template (a lot of comboboxes in listbox) and I want to handle enter button. It would be easy if it was e.g. a button - I would use Command + Relative binding path etc. Unfortunately, I have no idea how handle key press with a Command or how to set event handler from template. Any suggestions? You can use the EventSetter in the style you are setting the template with: <Style TargetType="{x:Type ListBoxItem}"> <EventSetter Event="MouseWheel" Handler="GroupListBox_MouseWheel" /> <Setter Property="Template" ... /> </Style> levanovd I've solved my problem by using

Binding a CollectionViewSource within a DataTemplate

风流意气都作罢 提交于 2019-11-29 01:46:20
'ContentTemplate' is a DataTemplate that displays an object which has a member 'FooList' (an ObservableCollection). <DataTemplate x:Key="ContentTemplate"> <ListBox ItemsSource="{Binding Path=FOO}"> ... </ListBox> </DataTemplate> I need to be able to filter that FooList using a CollectionViewSource. This is usually been straight forward but I can't seem to get the binding to work within a DataTemplate. I attempted to this: <DataTemplate x:Key="ContentTemplate"> <DataTemplate.Resources> <CollectionViewSource x:Key="CVS" Source="{Binding Path=FooList}" Filter="FooFilter"/> <DataTemplate.Resources

How to apply style trigger to datatemplate in WPF

十年热恋 提交于 2019-11-29 01:12:54
问题 I've got the following.. <ComboBox Grid.Row="2" Grid.Column="2" Grid.RowSpan="2" ItemsSource="{Binding ShipperAddresses}" Text="{Binding ShipperAddress}" Margin="85,2,0,2"> <ComboBox.ItemTemplate> <DataTemplate> <TextBox AcceptsReturn="True" Width="200" Height="100"/> <DataTemplate.Resources> <Style TargetType="{x:Type TextBox}"> <Setter Property="IsReadOnly" Value="True"> <Style.Triggers> <DataTrigger Binding="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type

How to Bind To Data within a Datatemplate of a ContentControl

非 Y 不嫁゛ 提交于 2019-11-29 00:37:49
问题 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> <