public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { Object result = new Object(); if (value != null) { try { Debug.Assert(value is Stop); // only stops can be input value in this converter Stop currentStop = (Stop)value; StopType type = (StopType)currentStop.StopType; ControlTemplate template = (ControlTemplate)App.Current.FindResource("OrderStopGlyph"); Grid grid = (Grid)template.LoadContent(); Path path = (Path)grid.Children[2]; Color color = Color.FromArgb(currentStop.Route.Color.A, currentStop.Route.Color.R, currentStop.Route.Color.G, currentStop.Route.Color.B); path.Fill = new SolidColorBrush(color); result = grid; } catch { result = null; } } else { result = null; } return(result); }
private Grid GetAndAssertGrid() { var grid = _buttonTemplate.LoadContent() as Grid; Assert.That(grid, Is.Not.Null, () => "The 'Content' of the 'ControlTemplate' should be a grid"); return(grid); }
/// <summary> /// Provides derived classes an opportunity to handle changes to the Template property. /// </summary> protected virtual void OnTemplateChanged(ControlTemplate oldTemplate, ControlTemplate newTemplate) { _mask = (FrameworkElement)newTemplate.LoadContent(); _canvas.Children.Clear(); _canvas.Children.Add(_mask); SetBindings(); }
protected virtual void OnTemplateChanged(ControlTemplate oldTemplate, ControlTemplate newTemplate) { if (newTemplate.TargetType != this.GetType()) { throw new ArgumentException(string.Format("Invalid TargetType expected {0} got {1}", this.GetType(), newTemplate.TargetType)); } if (this.controlTemplateInstance != null) { this.controlTemplateInstance.LayoutUpdated -= this.OnTemplateInstanceLayoutUpdated; this.RemoveControlTemplateInstance(); this.RemoveLogicalChild(this.controlTemplateInstance); } if (newTemplate != null) { this.controlTemplateInstance = (UIElement)newTemplate.LoadContent(); this.controlTemplateInstance.LayoutUpdated += this.OnTemplateInstanceLayoutUpdated; this.AddLogicalChild(this.controlTemplateInstance); this.AddControlTemplateInstance(); } else { this.controlTemplateInstance = null; this.NativeUIElement = null; this.NativeInit(); } this.OnLayoutUpdated(); }
private static CodeExpression GetControlTemplateValueExpression(CodeTypeDeclaration parentClass, CodeMemberMethod method, object value, string baseName) { ControlTemplate controlTemplate = value as ControlTemplate; DependencyObject content = controlTemplate.LoadContent(); string variableName = baseName + "_ct"; string creator = CodeComHelper.GenerateTemplate(parentClass, method, content, variableName); Type targetType = controlTemplate.TargetType; CodeVariableDeclarationStatement controlTemplateVar; if (targetType != null) { controlTemplateVar = new CodeVariableDeclarationStatement( "ControlTemplate", variableName, new CodeObjectCreateExpression("ControlTemplate", new CodeTypeOfExpression(targetType.Name), new CodeSnippetExpression(creator))); } else { controlTemplateVar = new CodeVariableDeclarationStatement( "ControlTemplate", variableName, new CodeObjectCreateExpression("ControlTemplate", new CodeSnippetExpression(creator))); } method.Statements.Add(controlTemplateVar); TriggerCollection triggers = controlTemplate.Triggers; CodeComHelper.GenerateTriggers(parentClass, method, variableName, targetType, triggers); return(new CodeVariableReferenceExpression(variableName)); }
private Border GetAndAssertBorder() { var border = _roundedCornerTextBoxTemplate.LoadContent() as Border; Assert.That(border, Is.Not.Null, "The 'Content' of the 'ControlTemplate' of the TextBox should be a border"); return(border); }
private Grid GetAndAssertGridOfPentagonTemplate() { Assert.That(_pentagonButtonTemplate, Is.Not.Null, "No template found for the pentagon button."); var grid = _pentagonButtonTemplate.LoadContent() as Grid; Assert.That(grid, Is.Not.Null, () => "The 'Content' of the 'ControlTemplate' of the pentagon Button should be a grid"); return(grid); }
internal static FrameworkElement LoadContent(this FrameworkElementFactory visualTree) { var template = new ControlTemplate() { VisualTree = visualTree }; template.Seal(); return(template.LoadContent() as FrameworkElement); }
private void UpdateDataGrid(ControlTemplate controlTemplate) { if (controlTemplate == null) { return; } var dataGrid = controlTemplate.LoadContent() as DataGrid; _dataGridContentControl.Content = dataGrid; }
/// <summary> /// Initializes a new instance of the <see cref="DataTemplateElement"/> class. /// </summary> /// <param name="controlTemplate">The data template.</param> /// <param name="boundType">Type of the bound.</param> /// <param name="baseName">Name of the base.</param> internal ControlTemplateElement(ControlTemplate controlTemplate, BoundType boundType, string baseName) : base(controlTemplate.LoadContent(), boundType) { this.controlTemplate = controlTemplate; if (this.controlTemplate.TargetType != null) { BaseName = baseName + " [ControlTemplate " + this.controlTemplate.TargetType.Name + "] "; } else { BaseName = baseName + " [ControlTemplate] "; } }
private Border GetAndAssertBorder() { var border = _buttonTemplate.LoadContent() as Border; Assert.That(border, Is.Not.Null, "The 'Content' of the 'ControlTemplate' should be a 'Border'."); Assert.That(border.Background, Is.Null, "The 'Border' should not have a background."); Assert.That(border.BorderBrush, Is.TypeOf <SolidColorBrush>(), "The 'BorderBrush' should be a solid color."); Assert.That(border.BorderThickness.Right > 0 && border.BorderThickness.Bottom > 0 && border.BorderThickness.Left > 0 && border.BorderThickness.Top > 0, Is.True, "The 'Border' should have a thickness on all sides."); Assert.That(border.CornerRadius.TopLeft > 0 && border.CornerRadius.TopRight > 0 && border.CornerRadius.BottomRight > 0 && border.CornerRadius.BottomLeft > 0, Is.True, "The 'Border' should have a corner radius on all sides."); return(border); }
protected void UpdateKeyboardControl() { VirtualKeyboardPresenter presenter = FindVirtualKeyboardPresenter(); if (presenter == null) { return; } ControlTemplate keyboardLayout = FindKeyboardLayout(); if (keyboardLayout == null) { ServiceRegistration.Get <ILogger>().Warn("VirtualKeyboardControl: Could not find style resource for virtual keyboard"); return; } FrameworkElement keyboardControl = keyboardLayout.LoadContent(this) as FrameworkElement; presenter.SetKeyboardLayoutControl(this, keyboardControl); }
void OnTemplateChanged(AbstractProperty property, object oldValue) { ControlTemplate template = Template; if (template != null) { Resources.Merge(template.Resources); FrameworkElement templateControl = template.LoadContent(this) as FrameworkElement; if (templateControl != null) { templateControl.LogicalParent = this; } TemplateControl = templateControl; } else { TemplateControl = null; } }
private void UpdateUIResources() { ResourceDictionary resources = new ResourceDictionary { Source = new Uri("/SS2Widget;component/Charts/Axes/AxisControlStyle.xaml", UriKind.Relative) }; AxisPlacement placement = GetBetterPlacement(this.placement); ControlTemplate template = (ControlTemplate)resources[templateKey + placement.ToString()]; Verify.AssertNotNull(template); var content = (FrameworkElement)template.LoadContent(); ticksPath = (Path)content.FindName(PART_TicksPath); ticksPath.SnapsToDevicePixels = true; Verify.AssertNotNull(ticksPath); commonLabelsCanvas = (StackCanvas)content.FindName(PART_CommonLabelsCanvas); Verify.AssertNotNull(commonLabelsCanvas); commonLabelsCanvas.Placement = placement; additionalLabelsCanvas = (StackCanvas)content.FindName(PART_AdditionalLabelsCanvas); Verify.AssertNotNull(additionalLabelsCanvas); additionalLabelsCanvas.Placement = placement; mainGrid = (Grid)content.FindName(PART_ContentsGrid); Verify.AssertNotNull(mainGrid); mainGrid.SetBinding(Control.BackgroundProperty, new Binding { Path = new PropertyPath("Background"), Source = this }); Content = mainGrid; string transformKey = additionalLabelTransformKey + placement.ToString(); if (resources.Contains(transformKey)) { additionalLabelTransform = (Transform)resources[transformKey]; } }
public void load(string player) { // get tiers filter List <string> tiers = auditTierComboBox.SelectedItemsOverride as List <string>; // if data loaded if (player != null && tabControl != null && tiers != null && Resources.Contains("AuditRecordsTemplate")) { DataGrid dataGrid = null; TabItem tabItem = tabControl.Items.Cast <TabItem>().FirstOrDefault(item => player.Equals(item.Header)); if (tabItem != null) { dataGrid = ((tabItem.Content as Grid).Children[0] as DataGrid); tabControl.SelectedItem = tabItem; } else { tabItem = new TabItem(); Grid grid = new Grid(); ControlTemplate template = (ControlTemplate)Resources["AuditRecordsTemplate"]; FrameworkElement elem = template.LoadContent() as FrameworkElement; if (elem != null) { elem.ApplyTemplate(); grid.Children.Add(elem); } tabItem.Content = grid; tabItem.Header = player; tabControl.Items.Add(tabItem); tabControl.SelectedItem = tabItem; dataGrid = (elem as DataGrid); } if (dataGrid != null) { dataGrid.ItemsSource = DataManager.getLootAudit(player, tiers, auditTimeSpinner.Value); } } }
/// <summary> /// Converts values. Create and return control template for necessary stop. /// </summary> /// <param name="value">Stop.</param> /// <param name="targetType">Type of input value.</param> /// <param name="parameter">Converter parameter.</param> /// <param name="culture">Curren localization settings.</param> /// <returns>Control template.</returns> public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture) { Debug.Assert(values != null); Debug.Assert(values.Length == BINDING_PARAMETERS_COUNT); // Count of input parameter must be equals 3 : Stop, IsViolated and Color value. // If any input parameter is null - return null. if (values[0] == null || values[1] == null) { return(null); } Stop currentStop = (Stop)values[0]; Debug.Assert(currentStop != null); // Workaround: on some unknown reason this converter is called even // if stop was unassigned from route, so we need additionally check // that stop belong to route. // If this condition isnt true then return no image. if (currentStop.Route == null) { return(new Grid()); } StopType currentStopType = currentStop.StopType; string templateResourceName = string.Empty; // Define ControlTemplate resource name for stop. if (currentStopType.Equals(StopType.Lunch)) { templateResourceName = BREAK_STOP_GLYPH; } else if (currentStopType.Equals(StopType.Location)) { templateResourceName = LOCATION_STOP_GLYPH; } else if (currentStopType.Equals(StopType.Order)) { templateResourceName = ORDER_STOP_GLYPH; } else { Debug.Assert(false); // Not supporter now. } Debug.Assert(currentStop.Route != null); // If stop is violated - use violated icon. if (currentStop.IsViolated) { templateResourceName = VIOLATED_STOP_GLYPH; } // Load ControlTemplate from necessary resource. ControlTemplate template = (ControlTemplate)App.Current.FindResource(templateResourceName); Debug.Assert(template != null); Grid grid = (Grid)template.LoadContent(); // If current stop is Order - define symbol color. if (templateResourceName == ORDER_STOP_GLYPH) { Path path = grid.Children[2] as Path; Debug.Assert(path != null); Color color = Color.FromArgb(currentStop.Route.Color.A, currentStop.Route.Color.R, currentStop.Route.Color.G, currentStop.Route.Color.B); path.Fill = new SolidColorBrush(color); } Object result = grid; return(result); }
private async void UserControl_Loaded(object sender, RoutedEventArgs e) { #region Draw Base objects if (CalendarData == null) { return; } if (CalendarData.canEdit && CalendarData.status == 0) // قابل ویرایش بود و پیش نویسی موجود نبود { BaseObject = new SaveDailyReportViewModel() { date = CalendarData.date, token = Common.Cache.CurrentUser.token, report = new Common.Model.DailyReportViewExtendModel() { dailyReportBankList = new List <DailyReportBankViewModel>(), dailyReportCurrencyList = new List <DailyReportCurrencyViewModel>() } }; } else if (CalendarData.canEdit && (CalendarData.status == 1 || CalendarData.status == 2)) // قابل ویرایش بود و پیش نویس وجود داشت { BaseObject = await LoadCalendarReportData(); } else if (!CalendarData.canEdit && CalendarData.status == 2)// قابل ویرایش نبود و اطلاعات ذخیره شده وجود داشت { BaseObject = await LoadCalendarReportData(); } else if (!CalendarData.canEdit && CalendarData.status == 0) // اگر قابل ویرایش نبود و نه پیش نویس داشت نه ذخیره :| { BaseObject = new Web.Areas.DailyReportFinancial.Models.SaveDailyReportViewModel() { date = CalendarData.date, token = Common.Cache.CurrentUser.token, report = new Common.Model.DailyReportViewExtendModel() { dailyReportBankList = new List <Web.Areas.DailyReportFinancial.Models.DailyReportBankViewModel>(), dailyReportCurrencyList = new List <Web.Areas.DailyReportFinancial.Models.DailyReportCurrencyViewModel>() } }; } this.DataContext = BaseObject.report; #endregion #region Bank List if (GrdBanks.RowDefinitions.Count == 0) { int i = 0; if (Common.Cache.BankList != null) { ControlTemplate BankTemplate = GrdBanks.Resources["BankTemplate"] as ControlTemplate; BaseObject.report.dailyReportBankList.Clear(); foreach (var bank in Common.Cache.BankList.OrderBy(x => x.id)) { GrdBanks.RowDefinitions.Add(new RowDefinition()); Grid grid = BankTemplate.LoadContent() as Grid; Grid.SetRow(grid, GrdBanks.RowDefinitions.Count - 1); GrdBanks.Children.Add(grid); Border brdTitle = (Border)grid.Children[0]; ((TextBlock)brdTitle.Child).Text = bank.name; BaseObject.report.dailyReportBankList.Add(new Common.Model.DailyReportBankViewExtendModel((Common.Model.DailyReportViewExtendModel)BaseObject.report) { bankId = bank.id }); Border brdExit = (Border)grid.Children[1]; BindingOperations.SetBinding(brdExit.Child, TextBox.TextProperty, new Binding($"dailyReportBankList[{i}].exit") { Mode = BindingMode.TwoWay, UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged }); Border brdEnter = (Border)grid.Children[2]; BindingOperations.SetBinding(brdEnter.Child, TextBox.TextProperty, new Binding($"dailyReportBankList[{i}].entry") { Mode = BindingMode.TwoWay, UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged }); Border brdUm = (Border)grid.Children[3]; BindingOperations.SetBinding(brdUm.Child, TextBlock.TextProperty, new Binding($"dailyReportBankList[{i++}].bankSum") { Mode = BindingMode.TwoWay, UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged }); } } } #endregion #region Currency List if (GrdCurrency.RowDefinitions.Count == 0) { int i = 0; if (Common.Cache.BankList != null) { ControlTemplate CurrencyTemplate = GrdCurrency.Resources["CurrencyTemplate"] as ControlTemplate; BaseObject.report.dailyReportCurrencyList.Clear(); foreach (var cur in Common.Cache.CurrencyList.OrderBy(x => x.id)) { GrdCurrency.RowDefinitions.Add(new RowDefinition()); Grid grid = CurrencyTemplate.LoadContent() as Grid; Grid.SetRow(grid, GrdCurrency.RowDefinitions.Count - 1); GrdCurrency.Children.Add(grid); Grid grd = (Grid)grid.Children[0]; Border brdTitle = (Border)grd.Children[0]; ((TextBlock)brdTitle.Child).Text = cur.name; BaseObject.report.dailyReportCurrencyList.Add(new Common.Model.DailyReportCurrencyViewExtendModel((Common.Model.DailyReportViewExtendModel)BaseObject.report) { currencyId = cur.id , }); Border brdValue = (Border)grd.Children[1]; BindingOperations.SetBinding(brdValue.Child, TextBox.TextProperty, new Binding($"dailyReportCurrencyList[{i}].value") { Mode = BindingMode.TwoWay, UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged }); Border brdExit = (Border)grid.Children[1]; BindingOperations.SetBinding(brdExit.Child, TextBox.TextProperty, new Binding($"dailyReportCurrencyList[{i}].rialExit") { Mode = BindingMode.TwoWay, UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged }); Border brdEnter = (Border)grid.Children[2]; BindingOperations.SetBinding(brdEnter.Child, TextBox.TextProperty, new Binding($"dailyReportCurrencyList[{i}].rialEntry") { Mode = BindingMode.TwoWay, UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged }); Border brdUm = (Border)grid.Children[3]; BindingOperations.SetBinding(brdUm.Child, TextBlock.TextProperty, new Binding($"dailyReportCurrencyList[{i++}].CurrencySum") { Mode = BindingMode.TwoWay, UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged }); } } } #endregion }
private void UpdateUIResources() { ResourceDictionary resources = new ResourceDictionary { Source = new Uri("/DynamicDataDisplay;component/Charts/Axes/AxisControlStyle.xaml", UriKind.Relative) }; AxisPlacement placement = GetBetterPlacement(this.placement); ControlTemplate template = (ControlTemplate)resources[templateKey + placement.ToString()]; Verify.AssertNotNull(template); var content = (FrameworkElement)template.LoadContent(); if (ticksPath != null && ticksPath.Data != null) { GeometryGroup group = (GeometryGroup)ticksPath.Data; foreach (var child in group.Children) { LineGeometry geometry = (LineGeometry)child; lineGeomPool.Put(geometry); } group.Children.Clear(); } ticksPath = (Path)content.FindName(PART_TicksPath); ticksPath.SnapsToDevicePixels = true; Verify.AssertNotNull(ticksPath); // as this method can be called not only on loading of axisControl, but when its placement changes, internal panels // can be not empty and their contents should be released if (commonLabelsCanvas != null && labelProvider != null) { foreach (UIElement child in commonLabelsCanvas.Children) { if (child != null) { labelProvider.ReleaseLabel(child); } } labels = null; commonLabelsCanvas.Children.Clear(); } commonLabelsCanvas = (StackCanvas)content.FindName(PART_CommonLabelsCanvas); Verify.AssertNotNull(commonLabelsCanvas); commonLabelsCanvas.Placement = placement; if (additionalLabelsCanvas != null && majorLabelProvider != null) { foreach (UIElement child in additionalLabelsCanvas.Children) { if (child != null) { majorLabelProvider.ReleaseLabel(child); } } } additionalLabelsCanvas = (StackCanvas)content.FindName(PART_AdditionalLabelsCanvas); Verify.AssertNotNull(additionalLabelsCanvas); additionalLabelsCanvas.Placement = placement; mainGrid = (Grid)content.FindName(PART_ContentsGrid); Verify.AssertNotNull(mainGrid); mainGrid.SetBinding(Control.BackgroundProperty, new Binding { Path = new PropertyPath("Background"), Source = this }); mainGrid.SizeChanged += new SizeChangedEventHandler(mainGrid_SizeChanged); Content = mainGrid; string transformKey = additionalLabelTransformKey + placement.ToString(); if (resources.Contains(transformKey)) { additionalLabelTransform = (Transform)resources[transformKey]; } }
/// <summary> /// Initializes a new instance of the <see cref="PivotSegmentEditor"/> class. /// </summary> public PivotSegmentEditor() { ResourceDictionary resources = new ResourceDictionary { Source = new Uri("/DynamicDataDisplay;component/Charts/Shapes/PivotSegmentEditor.xaml", UriKind.Relative) }; panel.BeginBatchAdd(); ControlTemplate segmentTemplate = (ControlTemplate)resources["segment"]; segment = (Segment)segmentTemplate.LoadContent(); segment.DataContext = this; ControlTemplate startThumbTemplate = (ControlTemplate)resources["leftThumb"]; startThumb = (DraggablePoint)startThumbTemplate.LoadContent(); startThumb.DataContext = this; ControlTemplate endThumbTemplate = (ControlTemplate)resources["rightThumb"]; endThumb = (DraggablePoint)endThumbTemplate.LoadContent(); endThumb.DataContext = this; ControlTemplate leftRayTemplate = (ControlTemplate)resources["leftRay"]; leftRay = (ViewportRay)leftRayTemplate.LoadContent(); leftRay.DataContext = this; ControlTemplate rightRayTemplate = (ControlTemplate)resources["rightRay"]; rightRay = (ViewportRay)rightRayTemplate.LoadContent(); rightRay.DataContext = this; ControlTemplate mTextTemplate = (ControlTemplate)resources["mText"]; TextBlock mText = (TextBlock)mTextTemplate.LoadContent(); panel.Children.Add(mText); mText.DataContext = this; ControlTemplate leftPointGridTemplate = (ControlTemplate)resources["leftPointGrid"]; Panel leftPointGrid = (Panel)leftPointGridTemplate.LoadContent(); panel.Children.Add(leftPointGrid); leftPointGrid.DataContext = this; ControlTemplate rightPointGridTemplate = (ControlTemplate)resources["rightPointGrid"]; Panel rightPointGrid = (Panel)rightPointGridTemplate.LoadContent(); panel.Children.Add(rightPointGrid); rightPointGrid.DataContext = this; ControlTemplate leftTextTemplate = (ControlTemplate)resources["leftText"]; FrameworkElement leftBorder = (FrameworkElement)leftTextTemplate.LoadContent(); panel.Children.Add(leftBorder); leftBorder.DataContext = this; ControlTemplate rightTextTemplate = (ControlTemplate)resources["rightText"]; FrameworkElement rightBorder = (FrameworkElement)rightTextTemplate.LoadContent(); panel.Children.Add(rightBorder); rightBorder.DataContext = this; }
protected void OnTemplateChanged(ControlTemplate oldTemplate, ControlTemplate newTemplate) { if (newTemplate.TargetType != this.GetType()) { throw new System.ArgumentException(string.Format("Invalid TargetType expected {0} got {1}", this.GetType(), newTemplate.TargetType)); } if (this.controlTemplateInstance != null) { this.controlTemplateInstance.LayoutUpdated -= this.ControlTemplateInstance_LayoutUpdated; this.RemoveControlTemplateInstance(); this.RemoveLogicalChild(this.controlTemplateInstance); } if (newTemplate != null) { this.controlTemplateInstance = (UIElement)newTemplate.LoadContent(); this.controlTemplateInstance.LayoutUpdated += this.ControlTemplateInstance_LayoutUpdated; this.AddLogicalChild(this.controlTemplateInstance); this.AddControlTemplateInstance(); } else { this.controlTemplateInstance = null; this.NativeUIElement = null; this.NativeInit(); } this.OnLayoutUpdated(); }