datatemplate

Generic DataTemplate used in multiple GridViewColumns

痴心易碎 提交于 2019-11-30 20:59:47
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"> <TextBlock Text="{Binding StringFormat={}{0:yyyy.MM.dd}}" /> </DataTemplate> Adding CellTemplate won't work

ContentControl with DataTemplateSelector - help needed

不羁岁月 提交于 2019-11-30 20:32:09
I got an enoying problem... Maybe someone can (please!) help. I am using a model that has and enumeration of types and a property that should hold UI models for each selected type from enumeration: Let's define them like: class ViewModel { Types selectedType{get;set;} UiModelBase editedModel{get;set;} } I want to have a content control that use datatemplateselector to change his view each time I change the selectedType. <ListBox x:Name="RuleTypeList" ItemsSource="{Binding Source={StaticResource Types}}" SelectedItem="{Binding Path=selectedType}"/> <!--Content control--> <ContentControl

Specifying DataTemplate.DataType with a custom type extension

自古美人都是妖i 提交于 2019-11-30 19:42:55
I have this markup extension public class NullableExtension : TypeExtension { public NullableExtension() { } public NullableExtension( string type ) : base(type) { } public NullableExtension( Type type ) : base(type) { } public override object ProvideValue( IServiceProvider serviceProvider ) { Type basis = (Type)base.ProvideValue( serviceProvider ); return typeof(Nullable<>).MakeGenericType( basis ); } } which is designed to provide a nullable version of some other type. It works as expected when used in "normal" XAML. For example, as in <SomeControl DataContext="{My:Nullable System:Int32}"/>

How can I bind an ObservableCollection to TextBoxes in a DataTemplate?

为君一笑 提交于 2019-11-30 18:55:13
I am trying to successfully TwoWay bind an ObservableCollection to TextBoxes in a DataTemplate. I can get the data to display properly, but I am unable to change the list data through the UI. I have a Model class named 'model' which contains an ObservableCollection named 'List'. The class implements the INotifyPropertyChanged interface. Here is the xaml for the shell. The DataContext for Window1's grid is set to "theGrid.DataContext=model" <Window x:Class="BindThat.Window1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

Binding to property in owning window's viewmodel within a DataTemplate in Window.Resources

一个人想着一个人 提交于 2019-11-30 18:44:51
问题 I have a DataTemplate within my Window's Resources section that creates a TextBlock with a ContextMenu. I want to be able to set whether a MenuItem within the ContextMenu is visible from within my Window's view model. I have tried accessing the DataContext of the Window by setting ElementName , and also tried setting RelativeSource , but both approaches resulted in binding errors. I'm not sure what else I can try. I have created a small example that shows what I'm trying to do: XAML: <Window

Binding a WPF Button CommandParameter to the Button itself in DataTemplate

纵饮孤独 提交于 2019-11-30 18:18:09
I have a DataTemplate that represents AppBar buttons that I declare through a collection of custom AppBarCommand objects. public AppBarCommand(RelayCommand command, string buttonstyle) { Command = command; ButtonStyle = buttonstyle; } <DataTemplate> <Button Command="{Binding Command}" Style="{Binding ButtonStyle, Converter={StaticResource StringNameToStyleConverter}}"/> </DataTemplate> I would like to add a CommandParameter binding, but the parameter has to be the Button itself. This is so I can set the PlacementTarget of a Callisto flyout. Is this possible? Miklós Balogh <Button Command="

How do I create a datatemplate with content programmatically?

偶尔善良 提交于 2019-11-30 17:28:31
I want to do the following at runtime in code: <DataTemplate x:Key="lightGreenRectangle"> <Rectangle Fill="LightGreen"/> </DataTemplate> So far I've got: public DataTemplate GetColouredRectangleInDataTemplate(Color colour) { DataTemplate dataTemplate = new dataTemplate(); return dataTemplate; } Help? I know this isn't the most elegant way of styling a control, but the component I want to specify a colour for has a property called "PointTemplate" of type DataTemplate. F Ruffell If for whatever reason you need to create a DataTemplate programmatically you would do: XAML: <Grid x:Name="myGrid">

Binding(Converter) in Code Behind

假如想象 提交于 2019-11-30 15:30:00
<local:LabelTemp x:Key="labelTemplate"/> <DataTemplate x:Key="labelTemp"> <TextBlock Text="{Binding Converter={StaticResource labelTemplate},Path=Item.Items}"/> </DataTemplate> Can anyone help me how to write the above Xaml code into Code Behind C#. Im using this code into Pie Chart LabelTemplate. I don't what is the binding source, or how the Pie Chart LabelTemplate (converter) look like. The best I can come up with that much information is the following: public class LabelTemplate : IValueConverter { public object Convert(object value, Type targetType, object parameter, System.Globalization

datatemplate in app.xaml is not getting picked up without any styles?

放肆的年华 提交于 2019-11-30 14:40:13
问题 I have a DataTemplate in app.xaml that binds a view to a viewmodel. <Application.Resources> <DataTemplate DataType="{x:Type vm:someviewmodeltype}"> <vw:somevwcontrol /> </DataTemplate> </Application.Resources> the above template doesn't get applied if there are no styles. The moment I put a style, something like ... <Application.Resources> <DataTemplate DataType="{x:Type vm:someviewmodeltype}"> <vw:somevwcontrol /> </DataTemplate> <Style TargetType="TextBlock"> <Setter Property="FontSize"

How to declare combobox itemTemplate that has Itemsource as Enum Values in WPF?

∥☆過路亽.° 提交于 2019-11-30 14:08:51
问题 I have a enum let's say enum MyEnum { FirstImage, SecondImage, ThirdImage, FourthImage }; I have binded this Enum to my combobox in XAML. While defining an combobox I have defined an ItemTemplate of combox to take Two UI element: TextBlock that show the enum value (Description) Image I have done this much in XAML. I am wondering where I can specify the Image corrosponding to each item of Enum value in a combobox? Is that possible through data trigger ? I really appreciate if anyone have the