private static EditorTemplateDefinition CreateNullableDateTimeOffsetEditor() { var binding = new Binding { Path = new PropertyPath("Value"), Mode = BindingMode.TwoWay }; var element = new FrameworkElementFactory(typeof(DateTimeOffsetEditor)); element.SetBinding(DateTimeOffsetEditor.OffsetProperty, binding); element.SetValue(BorderThicknessProperty, new Thickness(0)); element.SetValue(InputBase.TextAlignmentProperty, TextAlignment.Right); //element.SetValue(PartEditBox.CheckBoxVisibilityProperty, Visibility.Visible); element.SetValue(MarginProperty, new Thickness(5, 0, 0, 0)); var dataTemplate = new DataTemplate { VisualTree = element }; dataTemplate.Seal(); return(new EditorTemplateDefinition { EditingTemplate = dataTemplate, TargetProperties = { new TargetPropertyType { Type = typeof(DateTimeOffset?), } }, }); }
private static EditorTemplateDefinition CreateNullableTimeSpanEditor() { var binding = new Binding { Path = new PropertyPath("Value"), Mode = BindingMode.TwoWay }; var element = new FrameworkElementFactory(typeof(TimeSpanUpDown)); element.SetBinding(TimeSpanUpDown.ValueProperty, binding); //element.SetBinding(TimeSpanEditBox.InitialValueProperty, new Binding(".") { Converter = new DefaultValueConverter() }); element.SetValue(BorderThicknessProperty, new Thickness(0)); //element.SetValue(TimeSpanUpDown.FormatProperty, "d hh:mm:ss"); element.SetValue(InputBase.TextAlignmentProperty, TextAlignment.Right); //element.SetValue(PartEditBox.CheckBoxVisibilityProperty, Visibility.Visible); element.SetValue(MarginProperty, new Thickness(5, 0, 0, 0)); var dataTemplate = new DataTemplate { VisualTree = element }; dataTemplate.Seal(); return(new EditorTemplateDefinition { EditingTemplate = dataTemplate, TargetProperties = { new TargetPropertyType { Type = typeof(TimeSpan?), } }, }); }
private DataTemplate CreateContentDataTemplate(object item) { var factory = new FrameworkElementFactory(typeof(ContentControl)); factory.SetBinding(ContentControl.ContentProperty, new Binding() { Source = item }); factory.SetValue(ContentControl.FocusableProperty, false); factory.SetBinding(ContentControl.VerticalAlignmentProperty, new Binding() { RelativeSource = new RelativeSource(RelativeSourceMode.FindAncestor, typeof(IconPresenter), 1), Path = new PropertyPath(IconPresenter.VerticalContentAlignmentProperty) }); factory.SetBinding(ContentControl.HorizontalAlignmentProperty, new Binding() { RelativeSource = new RelativeSource(RelativeSourceMode.FindAncestor, typeof(IconPresenter), 1), Path = new PropertyPath(IconPresenter.HorizontalContentAlignmentProperty) }); var dataTemplate = new DataTemplate { VisualTree = factory }; dataTemplate.Seal(); return(dataTemplate); }
private static EditorTemplateDefinition CreateNullableEnumEditor <T>(bool isEditable = false) { var binding = new Binding { Path = new PropertyPath("Value"), Mode = BindingMode.TwoWay }; var element = new FrameworkElementFactory(typeof(EnumComboBox)); element.SetValue(EnumComboBox.EnumTypeProperty, typeof(T).GetUnderlyingType()); element.SetValue(ComboBox.IsEditableProperty, isEditable); element.SetBinding(Selector.SelectedValueProperty, binding); element.SetValue(BorderThicknessProperty, new Thickness(0)); element.SetValue(MarginProperty, new Thickness(0)); var dataTemplate = new DataTemplate { VisualTree = element }; dataTemplate.Seal(); return(new EditorTemplateDefinition { EditingTemplate = dataTemplate, TargetProperties = { new TargetPropertyType { Type = typeof(T) } }, }); }
/// <summary> /// simple mvvm implementation /// </summary> private static ResourceDictionary RegisterMapping() { var resourceDictionary = new ResourceDictionary(); resourceDictionary.BeginInit(); var types = typeof(Program).Assembly.GetTypes().Where(x => !x.IsAbstract && !x.IsNestedPrivate && !x.IsInterface && !x.IsEnum && x.Namespace?.StartsWith("Calc.ViewModels") == true) .ToArray(); var userControlType = typeof(UserControl); var viewTypes = types.Where(x => userControlType.IsAssignableFrom(x)); var modelTypes = types.Except(viewTypes).ToArray(); foreach (var modelType in modelTypes) { var viewName = modelType.Name + "View"; var viewType = viewTypes.FirstOrDefault(x => x.Name == viewName) ?? throw new Exception( $"View {viewName} not found for ViewModel {modelType}, ViewModels namespace only for ViewModels"); var template = new DataTemplate(modelType); var root = new FrameworkElementFactory(viewType); template.VisualTree = root; root.AddHandler(FrameworkElement.LoadedEvent, new RoutedEventHandler(Loaded)); resourceDictionary.Add(template.DataTemplateKey, template); template.Seal(); } resourceDictionary.EndInit(); return(resourceDictionary); }
private DataTemplate CreateImageDataTemplate(object item) { var factory = new FrameworkElementFactory(typeof(Image)); var imageSource = new Binding() { Source = item }; factory.SetBinding(Image.SourceProperty, imageSource); factory.SetBinding(Image.VerticalAlignmentProperty, new Binding() { RelativeSource = new RelativeSource(RelativeSourceMode.TemplatedParent), Path = new PropertyPath(ContentControl.VerticalContentAlignmentProperty) }); factory.SetBinding(Image.HorizontalAlignmentProperty, new Binding() { RelativeSource = new RelativeSource(RelativeSourceMode.TemplatedParent), Path = new PropertyPath(ContentControl.HorizontalContentAlignmentProperty) }); factory.SetValue(Image.FocusableProperty, false); factory.SetValue(RenderOptions.BitmapScalingModeProperty, BitmapScalingMode.HighQuality); var dataTemplate = new DataTemplate { VisualTree = factory }; dataTemplate.Seal(); return(dataTemplate); }
// Token: 0x060043EF RID: 17391 RVA: 0x00135F84 File Offset: 0x00134184 static ContentPresenter() { DataTemplate dataTemplate = new DataTemplate(); FrameworkElementFactory frameworkElementFactory = ContentPresenter.CreateAccessTextFactory(); frameworkElementFactory.SetValue(AccessText.TextProperty, new TemplateBindingExtension(ContentPresenter.ContentProperty)); dataTemplate.VisualTree = frameworkElementFactory; dataTemplate.Seal(); ContentPresenter.s_AccessTextTemplate = dataTemplate; dataTemplate = new DataTemplate(); frameworkElementFactory = ContentPresenter.CreateTextBlockFactory(); frameworkElementFactory.SetValue(TextBlock.TextProperty, new TemplateBindingExtension(ContentPresenter.ContentProperty)); dataTemplate.VisualTree = frameworkElementFactory; dataTemplate.Seal(); ContentPresenter.s_StringTemplate = dataTemplate; dataTemplate = new DataTemplate(); frameworkElementFactory = ContentPresenter.CreateTextBlockFactory(); Binding binding = new Binding(); binding.XPath = "."; frameworkElementFactory.SetBinding(TextBlock.TextProperty, binding); dataTemplate.VisualTree = frameworkElementFactory; dataTemplate.Seal(); ContentPresenter.s_XmlNodeTemplate = dataTemplate; dataTemplate = new ContentPresenter.UseContentTemplate(); dataTemplate.Seal(); ContentPresenter.s_UIElementTemplate = dataTemplate; dataTemplate = new ContentPresenter.DefaultTemplate(); dataTemplate.Seal(); ContentPresenter.s_DefaultTemplate = dataTemplate; ContentPresenter.s_DefaultTemplateSelector = new ContentPresenter.DefaultSelector(); }
private DataTemplate CreateDataTemplate(Color color) { #if SILVERLIGHT return((DataTemplate)XamlReader.Load( @"<DataTemplate xmlns=""http://schemas.microsoft.com/client/2007""> <Border BorderThickness=""1 1 0 0"" BorderBrush=""LightGray"" Background=""" + color.ToString() + @"""> <TextBlock Text=""{Binding Data, Mode=OneWay}"" Margin=""4"" VerticalAlignment=""Center"" HorizontalAlignment=""Right""/> </Border> </DataTemplate>" )); #else FrameworkElementFactory border = new FrameworkElementFactory(typeof(Border)); border.SetValue(Border.BorderThicknessProperty, new Thickness(1, 1, 0, 0)); border.SetValue(Border.BorderBrushProperty, Brushes.LightGray); border.SetValue(Border.BackgroundProperty, new SolidColorBrush(color)); DataTemplate dataTemplate = new DataTemplate(); dataTemplate.VisualTree = border; FrameworkElementFactory textBlock = new FrameworkElementFactory(typeof(TextBlock)); textBlock.SetBinding(TextBlock.TextProperty, new Binding("Data")); textBlock.SetValue(TextBlock.MarginProperty, new Thickness(2)); textBlock.SetValue(TextBlock.VerticalAlignmentProperty, VerticalAlignment.Center); textBlock.SetValue(TextBlock.HorizontalAlignmentProperty, HorizontalAlignment.Right); border.AppendChild(textBlock); dataTemplate.Seal(); return(dataTemplate); #endif }
internal static DataTemplate CreateFallbackViewTemplate(string errorText) { var factory = new FrameworkElementFactory(typeof(FallbackView)); factory.SetValue(FallbackView.TextProperty, errorText); var res = new DataTemplate() { VisualTree = factory }; res.Seal(); return res; }
private DataTemplate createFlagEnumEditorDataTemplate(ItemPropertyInfo itemProperty) { var flagEnumEditor = new FrameworkElementFactory(typeof(Telerik.Extensions.Controls.NamedFlagEnumEditor)); flagEnumEditor.SetValue(Telerik.Extensions.Controls.NamedFlagEnumEditor.EnumTypeProperty, itemProperty.PropertyType); //!@note RadPropertyGridのSourceItemsにEnumerableを渡す場合はCurrentPropertySet[{propertyName}]. // 単一のインスタンスの場合は{propertyName}をバインドターゲットにする必要がある. IValueConverter enumConverter; if (!_enumConverterMap.TryGetValue(itemProperty.PropertyType, out enumConverter)) { enumConverter = new EnumConverter(itemProperty.PropertyType); } #if true flagEnumEditor.SetBinding(Telerik.Extensions.Controls.NamedFlagEnumEditor.ValueProperty, new Binding($"CurrentPropertySet[{ itemProperty.Name }]") { Mode = BindingMode.TwoWay }); #else flagEnumEditor.SetBinding(Telerik.Extensions.Controls.NamedFlagEnumEdito2r.ValueProperty, new Binding($"{ propertyName }") { Mode = BindingMode.TwoWay, Converter = enumConverter }); #endif var dataTemplate = new DataTemplate(); dataTemplate.VisualTree = flagEnumEditor; dataTemplate.Seal(); return(dataTemplate); }
/// <summary> /// Override this method to return an app specific <seealso cref="DataTemplate"/>. /// </summary> /// <param name="item">The data content</param> /// <param name="container">The container in which the content is to be displayed</param> /// <returns>a app specific template to apply.</returns> public override DataTemplate SelectTemplate(object item, DependencyObject container) { if (SystemXmlHelper.IsXmlNode(item)) { if (_xmlNodeContentTemplate == null) { _xmlNodeContentTemplate = new DataTemplate(); FrameworkElementFactory text = ContentPresenter.CreateTextBlockFactory(); Binding binding = new Binding(); binding.XPath = _displayMemberPath; binding.StringFormat = _stringFormat; text.SetBinding(TextBlock.TextProperty, binding); _xmlNodeContentTemplate.VisualTree = text; _xmlNodeContentTemplate.Seal(); } return(_xmlNodeContentTemplate); } else { if (_clrNodeContentTemplate == null) { _clrNodeContentTemplate = new DataTemplate(); FrameworkElementFactory text = ContentPresenter.CreateTextBlockFactory(); Binding binding = new Binding(); binding.Path = new PropertyPath(_displayMemberPath); binding.StringFormat = _stringFormat; text.SetBinding(TextBlock.TextProperty, binding); _clrNodeContentTemplate.VisualTree = text; _clrNodeContentTemplate.Seal(); } return(_clrNodeContentTemplate); } }
static void OnBehaviorsTemplateChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { BehaviorCollection objectBehaviors = GetBehaviors(d); IList <Behavior> oldItems = d.GetValue(BehaviorsTemplateItemsProperty) as IList <Behavior>; DataTemplate newValue = e.NewValue as DataTemplate; if (oldItems != null) { foreach (Behavior behavior in oldItems) { if (objectBehaviors.Contains(behavior)) { objectBehaviors.Remove(behavior); } } } if (newValue == null) { d.SetValue(BehaviorsTemplateItemsProperty, null); return; } #if !NETFX_CORE if (!newValue.IsSealed) { newValue.Seal(); } #endif IList <Behavior> newItems; DependencyObject content = newValue.LoadContent(); if (content is ContentControl) { newItems = new List <Behavior>(); var behavior = ((ContentControl)content).Content as Behavior; ((ContentControl)content).Content = null; if (behavior != null) { newItems.Add(behavior); } } else if (content is ItemsControl) { var ic = content as ItemsControl; newItems = ic.Items.OfType <Behavior>().ToList(); ic.Items.Clear(); ic.ItemsSource = null; } else { throw new InvalidOperationException("Use ContentControl or ItemsControl in the template to specify Behaviors."); } d.SetValue(BehaviorsTemplateItemsProperty, newItems.Count > 0 ? newItems : null); foreach (Behavior behavior in newItems) { objectBehaviors.Add(behavior); } }
/// <summary> /// Creates a bound data template. /// </summary> /// <param name="dataTemplate">The data template.</param> /// <param name="boundType">Type of the bound object.</param> /// <param name="baseName">A base name.</param> /// <returns></returns> public static IBoundElement DataTemplate(DataTemplate dataTemplate, BoundType boundType, string baseName) { if (!dataTemplate.IsSealed) { dataTemplate.Seal(); } return(new DataTemplateElement(dataTemplate, boundType, baseName)); }
protected override void OnViewTemplateChanged(DataTemplate oldValue, DataTemplate newValue) { base.OnViewTemplateChanged(oldValue, newValue); if (newValue != null) { newValue.Seal(); } }
public void AddDataTemplate(DataTemplate dt) { if (this._Templates.Contains(dt)) { return; } dt.Seal(); this._Templates.Add(dt); }
private static DataTemplate TrySeal(DataTemplate template) { if ((template != null) && !template.IsSealed) { template.Seal(); } return(template); }
private static void OnTemplateChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { DataTemplate dt = (DataTemplate)e.NewValue; if (dt != null) { dt.Seal(); RoutedEventTrigger ih = (RoutedEventTrigger)dt.LoadContent(); (d as FrameworkElement).AddHandler(ih.RoutedEvent, new RoutedEventHandler(ih.OnRoutedEvent)); } }
private static DataTemplate CreateDefaultSpacerTemplate() { FrameworkElementFactory feFactory = new FrameworkElementFactory(typeof(VerticalConnector)); DataTemplate dt = new DataTemplate() { VisualTree = feFactory }; dt.Seal(); return(dt); }
public static DataTemplate CreateViewTemplate(this IViewLocator viewLocator, Type viewType) { Verify(viewLocator); if(viewType == null) throw new ArgumentNullException("viewType"); DataTemplate res = null; try { res = new DataTemplate() { VisualTree = new FrameworkElementFactory(viewType) }; res.Seal(); } catch { res = CreateFallbackViewTemplate(GetErrorMessage_CannotCreateDataTemplateFromViewType(viewType.Name)); } return res; }
private void InitializeResources() { var vmFactory = new FrameworkElementFactory(typeof(ViewModelViewHost)); vmFactory.SetBinding(ViewModelViewHost.ViewModelProperty, new Binding(".")); var vmTemplate = new DataTemplate(typeof(ReactiveObject)) { VisualTree = vmFactory }; vmTemplate.Seal(); Resources.Add(new DataTemplateKey(typeof(ReactiveObject)), vmTemplate); }
/// <summary> /// Returns the <see cref="DataTemplate"/> for defined view template. /// </summary> /// <returns>The generated <see cref="DataTemplate"/>.</returns> internal DataTemplate ProvideTemplate() { if (template == null && viewType != null) { template = TemplateFactory.CreateTemplate(viewType); template.DataType = modelType; template.Seal(); } return(template); }
internal static DataTemplate CreateFallbackViewTemplate(string errorText) { var factory = new FrameworkElementFactory(typeof(FallbackView)); factory.SetValue(FallbackView.TextProperty, errorText); var res = new DataTemplate() { VisualTree = factory }; res.Seal(); return(res); }
static ValueLineConfigurator() { ComboEnumDescriptionTemplate = new DataTemplate { VisualTree = new FrameworkElementFactory(typeof(TextBlock)) .Do(f => f.SetValue(TextBlock.TextAlignmentProperty, TextAlignment.Right)) .Do(f => f.SetBinding(TextBlock.TextProperty, new Binding() { Mode = BindingMode.OneTime, Converter = Converters.EnumDescription })) }; ComboEnumDescriptionTemplate.Seal(); }
static TreeGridContentColumnDefinition() { var template = new DataTemplate(); template.VisualTree = new FrameworkElementFactory(typeof(ContentControl)); template.VisualTree.SetBinding(ContentControl.ContentProperty, new Binding()); template.Seal(); ItemTemplateProperty.OverrideMetadata(typeof(TreeGridContentColumnDefinition), new PropertyMetadata(template)); DefaultStyleKeyProperty.OverrideMetadata(typeof(TreeGridContentColumnDefinition), new FrameworkPropertyMetadata(typeof(TreeGridContentColumnDefinition))); }
private static DataTemplate ToDataTemplate(Control icon) { var template = new DataTemplate(); var content = new FrameworkElementFactory(typeof(ContentControl)); content.SetBinding(ContentControl.ContentProperty, new Binding() { Source = icon }); template.VisualTree = content; template.Seal(); return(template); }
/// <summary> /// Initializes the <see cref="TypeBasedDataTemplateSelector"/> class. /// </summary> static ModelItemTemplateSelector() { DefaultDataTemplate = new DataTemplate(); var factory = new FrameworkElementFactory(typeof(TextBlock)); var propertyPath = new Binding() { StringFormat = "Cannot find template for type {0}. Optionally set the DataTemplate's x:Key property is set with the full name of this type." }; factory.SetBinding(TextBlock.TextProperty, propertyPath); factory.SetValue(TextBlock.TextWrappingProperty, TextWrapping.Wrap); factory.SetValue(TextBlock.ForegroundProperty, Brushes.Red); DefaultDataTemplate.VisualTree = factory; DefaultDataTemplate.Seal(); }
private DataTemplate CreateContentDataTemplate(object item) { var factory = new FrameworkElementFactory(typeof(ContentControl)); factory.SetBinding(ContentControl.ContentProperty, new Binding() { Source = item }); var dataTemplate = new DataTemplate { VisualTree = factory }; dataTemplate.Seal(); return(dataTemplate); }
public void BehaviorShouldNotBeFrozen_Test01_T196013() { var content = new FrameworkElementFactory(typeof(ContentControl)); content.SetValue(ContentControl.ContentProperty, new FakeBehavior()); var template = new DataTemplate() { VisualTree = content }; template.Seal(); var behavior = ((ContentControl)template.LoadContent()).Content as Behavior; Assert.IsFalse(behavior.IsFrozen); Assert.IsFalse(behavior.CanFreeze); }
/// <summary> /// Initializes the static version of <see cref="TransitionElement"/>. /// </summary> static TransitionElement() { // TraceSwitches.Transitions.Level = TraceLevel.Verbose; defaultNullContentTemplate = new DataTemplate(); FrameworkElementFactory rectangle = new FrameworkElementFactory(typeof(Rectangle)); rectangle.SetValue(FrameworkElement.HorizontalAlignmentProperty, HorizontalAlignment.Stretch); rectangle.SetValue(FrameworkElement.VerticalAlignmentProperty, VerticalAlignment.Stretch); rectangle.SetValue(Shape.FillProperty, SystemColors.WindowBrush /*new TemplateBindingExtension(Control.ForegroundProperty)?*/); defaultNullContentTemplate.VisualTree = rectangle; defaultNullContentTemplate.Seal(); NullContentTemplateProperty.OverrideMetadata(typeof(TransitionElement), new FrameworkPropertyMetadata(defaultNullContentTemplate)); ClipToBoundsProperty.OverrideMetadata(typeof(TransitionElement), new FrameworkPropertyMetadata(null, CoerceClipToBounds)); }
//------------------------------------------------------ // // Constructors // //------------------------------------------------------ static ContentPresenter() { DataTemplate template; FrameworkElementFactory text; Binding binding; // Default template for strings when hosted in ContentPresener with RecognizesAccessKey=true template = new DataTemplate(); text = CreateAccessTextFactory(); text.SetValue(AccessText.TextProperty, new TemplateBindingExtension(ContentProperty)); template.VisualTree = text; template.Seal(); s_AccessTextTemplate = template; // Default template for strings template = new DataTemplate(); text = CreateTextBlockFactory(); text.SetValue(TextBlock.TextProperty, new TemplateBindingExtension(ContentProperty)); template.VisualTree = text; template.Seal(); s_StringTemplate = template; // Default template for XmlNodes template = new DataTemplate(); text = CreateTextBlockFactory(); binding = new Binding(); binding.XPath = "."; text.SetBinding(TextBlock.TextProperty, binding); template.VisualTree = text; template.Seal(); s_XmlNodeTemplate = template; // Default template for UIElements template = new UseContentTemplate(); template.Seal(); s_UIElementTemplate = template; // Default template for everything else template = new DefaultTemplate(); template.Seal(); s_DefaultTemplate = template; // Default template selector s_DefaultTemplateSelector = new DefaultSelector(); }
private DataTemplate ProvideInlineTemplate() { DataTemplate dataTemplate = new DataTemplate(); FrameworkElementFactory frameworkElementFactory = new FrameworkElementFactory(typeof(Grid)); frameworkElementFactory.SetValue(FrameworkElement.MinHeightProperty, (object)20.0); frameworkElementFactory.SetValue(ClickBehavior.MouseClickCommandProperty, (object)PropertyValueEditorCommands.ShowExtendedPopupEditor); FrameworkElementFactory child = new FrameworkElementFactory(typeof(TextBlock)); child.SetValue(FrameworkElement.VerticalAlignmentProperty, (object)VerticalAlignment.Center); Binding binding = new Binding("StringValue"); child.SetValue(TextBlock.TextProperty, (object)binding); frameworkElementFactory.AppendChild(child); dataTemplate.VisualTree = frameworkElementFactory; dataTemplate.Seal(); return(dataTemplate); }
private DataTemplate CreateIconImageDataTemplate(object item) { var factory = new FrameworkElementFactory(typeof(Image)); var imageSource = new Binding() { Source = item, Converter = new IconToImageSourceConverter() }; factory.SetBinding(Image.SourceProperty, imageSource); factory.SetValue(RenderOptions.BitmapScalingModeProperty, BitmapScalingMode.HighQuality); var dataTemplate = new DataTemplate { VisualTree = factory }; dataTemplate.Seal(); return(dataTemplate); }