private void AddMaterialField(MaterialFieldModel materialField) { materialField.PropertyChanged += (s, e) => OnPropertyChanged("MaterialField"); MaterialFields.Add(materialField); }
public void AddNewMaterialField() { var materialField = new MaterialFieldModel("CustomField", Resources.CustomFieldText, DefaultFont); AddMaterialField(materialField); }
private TextBlock CreateTextBlock(MaterialFieldModel materialField) { var textBlock = new TextBlock { Tag = materialField, DataContext = materialField, Margin = new Thickness(0), Focusable = CanManipulateTexts }; if (CanManipulateTexts) { textBlock.Cursor = Cursors.Hand; textBlock.PreviewKeyUp += element_PreviewKeyUp; } var fontFamilyBinding = new Binding( $"{nameof(materialField.FontFamilyWithName)}.{nameof(materialField.FontFamilyWithName.FontFamily)}") { Mode = BindingMode.OneWay }; textBlock.SetBinding(TextBlock.FontFamilyProperty, fontFamilyBinding); var textColorBinding = new Binding(nameof(materialField.TextColor)) {Mode = BindingMode.OneWay}; textBlock.SetBinding(TextBlock.ForegroundProperty, textColorBinding); var fontStyleBinding = new Binding(nameof(materialField.Italic)) { Mode = BindingMode.OneWay, Converter = new FontStyleConverter() }; textBlock.SetBinding(TextBlock.FontStyleProperty, fontStyleBinding); var fontWeightBinding = new Binding(nameof(materialField.Bold)) { Mode = BindingMode.OneWay, Converter = new FontWeightConverter() }; textBlock.SetBinding(TextBlock.FontWeightProperty, fontWeightBinding); var fontSizeBinding = new Binding(nameof(materialField.FontSize)) {Mode = BindingMode.OneWay}; textBlock.SetBinding(TextBlock.FontSizeProperty, fontSizeBinding); var textBinding = new Binding(nameof(materialField.DisplayValue)) {Mode = BindingMode.OneWay}; textBlock.SetBinding(TextBlock.TextProperty, textBinding); var topBinding = new Binding(nameof(materialField.TopMargin)) {Mode = BindingMode.TwoWay}; textBlock.SetBinding(TopProperty, topBinding); var leftBinding = new Binding(nameof(materialField.LeftMargin)) {Mode = BindingMode.TwoWay}; textBlock.SetBinding(LeftProperty, leftBinding); textBlock.SetValue(AutomationProperties.AutomationIdProperty, "CanvasTextBlock"); Children.Add(textBlock); return textBlock; }