private DataTemplate CreateItemTemplate() { var template = new DataTemplate(); template.VisualTree = new FrameworkElementFactory(typeof(StackPanel)); var txtBlock = new FrameworkElementFactory(typeof(TextBlock)); txtBlock.SetBinding(TextBlock.TextProperty, new Binding("Street1")); template.VisualTree.AppendChild(txtBlock); txtBlock = new FrameworkElementFactory(typeof(TextBlock)); txtBlock.SetBinding(TextBlock.TextProperty, new Binding("City")); template.VisualTree.AppendChild(txtBlock); var trigger = new MultiDataTrigger(); trigger.Conditions.Add( new Condition( new Binding("Cty"), //misspelling "Tallahassee" ) ); trigger.Conditions.Add( new Condition( new Binding("StateOrProvince"), "Florida" ) ); template.Triggers.Add(trigger); return template; }
public static sw.FrameworkElementFactory EditableBlock(swd.RelativeSource relativeSource) { var factory = new sw.FrameworkElementFactory(typeof(EditableTextBlock)); var binding = new sw.Data.Binding { Path = TextPath, RelativeSource = relativeSource, Mode = swd.BindingMode.TwoWay, UpdateSourceTrigger = swd.UpdateSourceTrigger.PropertyChanged }; factory.SetBinding(EditableTextBlock.TextProperty, binding); return factory; }
private static DataTemplate CreateTemplate() { DataTemplate template = new DataTemplate {DataType = typeof(UiDataProviderNode)}; FrameworkElementFactory stackPanel = new FrameworkElementFactory(typeof(StackPanel)); stackPanel.SetValue(StackPanel.OrientationProperty, Orientation.Horizontal); FrameworkElementFactory image = new FrameworkElementFactory(typeof(Image)); image.SetValue(HeightProperty, 16d); image.SetValue(Image.SourceProperty, new Binding("Icon")); image.SetValue(MarginProperty, new Thickness(3)); stackPanel.AppendChild(image); //FrameworkElementFactory icon = new FrameworkElementFactory(typeof(ContentPresenter)); //icon.SetValue(HeightProperty, 16d); //icon.SetValue(ContentPresenter.ContentProperty, new Binding("Icon")); //icon.SetValue(MarginProperty, new Thickness(3)); //stackPanel.AppendChild(icon); FrameworkElementFactory textBlock = new FrameworkElementFactory(typeof(TextBlock)); textBlock.SetBinding(TextBlock.TextProperty, new Binding("Title")); textBlock.SetBinding(ToolTipProperty, new Binding("Description")); textBlock.SetValue(MarginProperty, new Thickness(3)); stackPanel.AppendChild(textBlock); template.VisualTree = stackPanel; return template; }
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { var template = value as Xamarin.Forms.DataTemplate; var uc = new FrameworkElementFactory(typeof(UserControl)); if (template != null) { uc.SetBinding(UserControl.ContentProperty, new MultiBinding { Converter = new CellToViewConverter(), Bindings = { new Binding(), new Binding { Source = template } } }); } else { uc.SetBinding(UserControl.ContentProperty, new Binding { Converter = new ModelToViewConverter() }); } return new DataTemplate { VisualTree = uc }; }
public static sw.FrameworkElementFactory TextBlock () { var factory = new sw.FrameworkElementFactory (typeof (swc.TextBlock)); factory.SetBinding (swc.TextBlock.TextProperty, new sw.Data.Binding { Path = new sw.PropertyPath("Text"), Mode = swd.BindingMode.TwoWay }); factory.SetBinding(swc.TextBlock.ForegroundProperty, new sw.Data.Binding { Path = new sw.PropertyPath("TextColor"), Mode = swd.BindingMode.OneWay, Converter = new ColorConverter() }); return factory; }
public TreeGridViewColumn() : base() { ResourceDictionary resourceDictionary = new ResourceDictionary(); resourceDictionary.Source = new Uri("pack://application:,,,/Yuhan.WPF.TreeListView;component/Resources/TreeListView.xaml"); //this.CellTemplate = resourceDictionary["CellTemplate"] as DataTemplate; DataTemplate template = new DataTemplate(); FrameworkElementFactory factory = new FrameworkElementFactory(typeof(DockPanel)); Expander = new FrameworkElementFactory(typeof(ToggleButton)); Expander.Name = "Expander"; Expander.SetValue(ToggleButton.StyleProperty, resourceDictionary["ExpandCollapseToggleStyle"] as Style); Expander.SetBinding(ToggleButton.VisibilityProperty, new Binding() { Source = this.Expandable, Converter = new BooleanToVisibilityConverter() }); Expander.SetBinding(ToggleButton.MarginProperty, new Binding("Level") { Converter = new LevelToIndentConverter(), RelativeSource = new RelativeSource(RelativeSourceMode.FindAncestor, typeof(TreeListViewItem), 1) }); Expander.SetBinding(ToggleButton.IsCheckedProperty, new Binding("IsExpanded") { RelativeSource = new RelativeSource(RelativeSourceMode.FindAncestor, typeof(TreeListViewItem), 1) }); Expander.SetValue(ToggleButton.ClickModeProperty, ClickMode.Press); ContentControlFactory = new FrameworkElementFactory(typeof(ContentControl)); ContentControlFactory.SetBinding(ContentControl.ContentProperty, new Binding(FieldName)); factory.AppendChild(Expander); factory.AppendChild(ContentControlFactory); template.VisualTree = factory; template.Triggers.Add(new DataTrigger() { Binding = new Binding("HasItems") { RelativeSource = new RelativeSource(RelativeSourceMode.FindAncestor, typeof(TreeListViewItem), 1), }, Value = false, Setters = { new Setter(ToggleButton.VisibilityProperty, Visibility.Hidden, "Expander") } }); this.CellTemplate = template; }
void UcTableView_SizeChanged(object sender, SizeChangedEventArgs e) { if (dt == null) { return; } _gridview.Columns.Clear(); foreach (DataColumn c in dt.Columns) { GridViewColumn gvc = new GridViewColumn(); gvc.Header = c.ColumnName; if (BShowDetails) { gvc.Width = (_listview.ActualWidth - 65) / dt.Columns.Count; } else { gvc.Width = (_listview.ActualWidth - 25) / dt.Columns.Count; } gvc.SetValue(HorizontalAlignmentProperty, HorizontalAlignment.Center); //gvc.DisplayMemberBinding = (new Binding(c.ColumnName)); FrameworkElementFactory text = new FrameworkElementFactory(typeof(TextBlock)); text.SetValue(TextBlock.HorizontalAlignmentProperty, HorizontalAlignment.Center); text.SetValue(TextBlock.TextAlignmentProperty, TextAlignment.Center); text.SetBinding(TextBlock.TextProperty, new Binding(c.ColumnName)); DataTemplate dataTemplate = new DataTemplate() { VisualTree = text }; gvc.CellTemplate = dataTemplate; _gridview.Columns.Add(gvc); } if (BShowDetails) { GridViewColumn gvc_details = new GridViewColumn(); gvc_details.Header = "详情"; FrameworkElementFactory button_details = new FrameworkElementFactory(typeof(Button)); button_details.SetResourceReference(Button.HorizontalContentAlignmentProperty, HorizontalAlignment.Center); button_details.SetValue(Button.WidthProperty, 40.0); button_details.AddHandler(Button.ClickEvent, new RoutedEventHandler(details_Click)); button_details.SetBinding(Button.TagProperty, new Binding(dt.Columns[1].ColumnName)); button_details.SetValue(Button.ContentProperty, ">>"); button_details.SetValue(Button.ForegroundProperty, Brushes.Blue); button_details.SetValue(Button.FontSizeProperty, 14.0); button_details.SetBinding(Button.VisibilityProperty, new Binding(dt.Columns[0].ColumnName) { Converter = new VisibleBtnConverter() }); DataTemplate dataTemplate_details = new DataTemplate() { VisualTree = button_details }; gvc_details.CellTemplate = dataTemplate_details; _gridview.Columns.Add(gvc_details); } _listview.ItemsSource = null; _listview.ItemsSource = dt.DefaultView; }
static GroupByControl() { // This DefaultStyleKey will only be used in design-time. DefaultStyleKeyProperty.OverrideMetadata( typeof( GroupByControl ), new FrameworkPropertyMetadata( new Markup.ThemeKey( typeof( Views.TableView ), typeof( GroupByControl ) ) ) ); FrameworkElementFactory staircaseFactory = new FrameworkElementFactory( typeof( StaircasePanel ) ); ItemsPanelTemplate itemsPanelTemplate = new ItemsPanelTemplate( staircaseFactory ); RelativeSource ancestorSource = new RelativeSource( RelativeSourceMode.FindAncestor, typeof( GroupByControl ), 1 ); Binding binding = new Binding(); binding.Path = new PropertyPath( GroupByControl.ConnectionLineAlignmentProperty ); binding.Mode = BindingMode.OneWay; binding.RelativeSource = ancestorSource; staircaseFactory.SetBinding( StaircasePanel.ConnectionLineAlignmentProperty, binding ); binding = new Binding(); binding.Path = new PropertyPath( GroupByControl.ConnectionLineOffsetProperty ); binding.Mode = BindingMode.OneWay; binding.RelativeSource = ancestorSource; staircaseFactory.SetBinding( StaircasePanel.ConnectionLineOffsetProperty, binding ); binding = new Binding(); binding.Path = new PropertyPath( GroupByControl.ConnectionLinePenProperty ); binding.Mode = BindingMode.OneWay; binding.RelativeSource = ancestorSource; staircaseFactory.SetBinding( StaircasePanel.ConnectionLinePenProperty, binding ); binding = new Binding(); binding.Path = new PropertyPath( GroupByControl.StairHeightProperty ); binding.Mode = BindingMode.OneWay; binding.RelativeSource = ancestorSource; staircaseFactory.SetBinding( StaircasePanel.StairHeightProperty, binding ); binding = new Binding(); binding.Path = new PropertyPath( GroupByControl.StairSpacingProperty ); binding.Mode = BindingMode.OneWay; binding.RelativeSource = ancestorSource; staircaseFactory.SetBinding( StaircasePanel.StairSpacingProperty, binding ); itemsPanelTemplate.Seal(); ItemsControl.ItemsPanelProperty.OverrideMetadata( typeof( GroupByControl ), new FrameworkPropertyMetadata( itemsPanelTemplate ) ); DataGridControl.ParentDataGridControlPropertyKey.OverrideMetadata( typeof( GroupByControl ), new FrameworkPropertyMetadata( new PropertyChangedCallback( GroupByControl.ParentGridControlChangedCallback ) ) ); DataGridControl.DataGridContextPropertyKey.OverrideMetadata( typeof( GroupByControl ), new FrameworkPropertyMetadata( new PropertyChangedCallback( GroupByControl.DataGridContextChangedCallback ) ) ); FocusableProperty.OverrideMetadata( typeof( GroupByControl ), new FrameworkPropertyMetadata( false ) ); }
void ChangeIsDeleted() { if (_deletationType == LogicalDeletationType.All) { if (!IsColumnShown) { var gridViewColumn = new GridViewColumn(); gridViewColumn.Header = "Дата удаления"; gridViewColumn.Width = 150; var dataTemplate = new DataTemplate(); var txtElement = new FrameworkElementFactory(typeof(IsDeletedTextBlock)); dataTemplate.VisualTree = txtElement; var binding = new Binding(); var bindingPath = string.Format("RemovalDate"); binding.Path = new PropertyPath(bindingPath); binding.Mode = BindingMode.OneWay; txtElement.SetBinding(IsDeletedTextBlock.TextProperty, binding); gridViewColumn.CellTemplate = dataTemplate; ListViewLayoutManager.SetCanUserResize(gridViewColumn, false); gridView.Columns.Add(gridViewColumn); } } else if (IsColumnShown) { gridView.Columns.Remove(IsDeletedColumn); } }
private void ShowResourcesGained_DataContextChanged(object sender, DependencyPropertyChangedEventArgs e) { RollDiceAction rollDice = e.NewValue as RollDiceAction; Dictionary<GamePlayer, ResourceList> result = rollDice.PlayersResources; basePanel.Children.Clear(); foreach (KeyValuePair<GamePlayer, ResourceList> kvp in result) { // add list of resources ItemsControl resources = new ItemsControl(); FrameworkElementFactory stackPanelElement = new FrameworkElementFactory(typeof(StackPanel)); stackPanelElement.SetValue(StackPanel.OrientationProperty, Orientation.Horizontal); resources.ItemsPanel = new ItemsPanelTemplate() { VisualTree = stackPanelElement}; resources.Height = 90; Binding binding = new Binding() { Converter = new ResourceConverter() }; FrameworkElementFactory imageElement = new FrameworkElementFactory(typeof(Image)); imageElement.SetBinding(Image.SourceProperty, binding); imageElement.SetValue(Image.HeightProperty, 80.0); imageElement.SetValue(Image.WidthProperty, 80.0); resources.ItemTemplate = new DataTemplate() { VisualTree = imageElement }; basePanel.Children.Add(resources); resources.ItemsSource = kvp.Value; } }
internal static FrameworkElementFactory CreateBoundCellRenderer(CellView view, string dataPath = ".") { TextCellView textView = view as TextCellView; if (textView != null) { FrameworkElementFactory factory = new FrameworkElementFactory (typeof (SWC.TextBlock)); factory.SetValue (FrameworkElement.MarginProperty, CellMargins); if (textView.TextField != null) factory.SetBinding (SWC.TextBlock.TextProperty, new Binding (dataPath + "[" + textView.TextField.Index + "]")); return factory; } ImageCellView imageView = view as ImageCellView; if (imageView != null) { FrameworkElementFactory factory = new FrameworkElementFactory (typeof (ImageBox)); factory.SetValue (FrameworkElement.MarginProperty, CellMargins); if (imageView.ImageField != null) { var binding = new Binding (dataPath + "[" + imageView.ImageField.Index + "]") { Converter = new ImageToImageSourceConverter () }; factory.SetBinding (ImageBox.ImageSourceProperty, binding); } return factory; } throw new NotImplementedException (); }
public override DataTemplate SelectTemplate(object item, DependencyObject container) { var rule = item as RuleViewModel; if (rule == null) return null; FrameworkElementFactory checkBoxFactory = new FrameworkElementFactory(typeof(CheckBox)); Binding isCheckedBinding = new Binding("IsSelected") { Mode = BindingMode.TwoWay, UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged }; checkBoxFactory.SetBinding(CheckBox.IsCheckedProperty, isCheckedBinding); FrameworkElementFactory textBlockFactory = new FrameworkElementFactory(typeof(TextBlock)); textBlockFactory.SetValue(TextBlock.HorizontalAlignmentProperty, HorizontalAlignment.Center); textBlockFactory.SetValue(TextBlock.TextProperty, (rule.Index + 1).ToString()); textBlockFactory.SetValue(TextBlock.MarginProperty, new Thickness(0, 5, 0, 0)); FrameworkElementFactory stackPanelFactory = new FrameworkElementFactory(typeof(StackPanel)); stackPanelFactory.AppendChild(checkBoxFactory); stackPanelFactory.AppendChild(textBlockFactory); return new DataTemplate { VisualTree = stackPanelFactory }; }
private static void OnLogSourceChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { ListView listView = d as ListView; LogItemCollection collection = e.NewValue as LogItemCollection; listView.ItemsSource = collection; GridView gridView = listView.View as GridView; int count = 0; gridView.Columns.Clear(); foreach (var col in collection.Columns) { var cell = new FrameworkElementFactory(typeof(TextBlock)); cell.SetBinding(TextBlock.TextProperty, new Binding(string.Format("[{0}]", count++))); cell.SetValue(FrameworkElement.MarginProperty, new Thickness(0, 4, 0, 4)); gridView.Columns.Add( new GridViewColumn { Header = new TextBlock { Text = col, FontSize = 11, Margin = new Thickness(5, 4, 5, 4) }, CellTemplate = new DataTemplate { DataType = typeof(LogItemCollection), VisualTree = cell, } }); } }
public FrameworkElementFactory CreateOnOffServiceScheduleButtonTemplate() { FrameworkElementFactory buttonTemplate = new FrameworkElementFactory(typeof (CheckBox)); buttonTemplate.SetBinding(ToggleButton.IsCheckedProperty, new Binding("IsOn") { UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged, }); buttonTemplate.AddHandler( ToggleButton.CheckedEvent, new RoutedEventHandler((o, e) => { DataGridServiceScheduleView dataGridServiceScheduleView = ((FrameworkElement) o).DataContext as DataGridServiceScheduleView; if (dataGridServiceScheduleView != null) { dataGridServiceScheduleView.IsOn = true.ToString(); } })); buttonTemplate.AddHandler( ToggleButton.UncheckedEvent, new RoutedEventHandler((o, e) => { DataGridServiceScheduleView dataGridServiceScheduleView = ((FrameworkElement) o).DataContext as DataGridServiceScheduleView; if (dataGridServiceScheduleView != null) { dataGridServiceScheduleView.IsOn = false.ToString(); } })); return buttonTemplate; }
public TextureManager() { InitializeComponent(); DataGridTemplateColumn col = new DataGridTemplateColumn(); Binding imgBinding = new Binding("Name") { Converter = new Controls.PathToImageConverter() }; FrameworkElementFactory imgFactory = new FrameworkElementFactory(typeof(Image)); imgFactory.SetBinding(Image.SourceProperty, imgBinding); imgFactory.SetValue(Image.MaxHeightProperty, 64.0); imgFactory.SetValue(Image.MaxWidthProperty, 64.0); imgFactory.SetValue(Image.TagProperty, "PreviewImage"); ((DataGridTemplateColumn)col).CellTemplate = new DataTemplate(); ((DataGridTemplateColumn)col).CellTemplate.VisualTree = imgFactory; col.Header = "Preview"; gridView.Columns.Add(col); formStack.Children.Add(textureForm_ = new ReflectiveForm(typeof(Urho.Texture))); texTree.DataContext = Project.inst().Textures; texTree.SelectedItemChanged += texTree_SelectedItemChanged; gridView.DataContext = flat_ = Project.inst().Textures.GetFlat(); formStack.Children.Add(nothing_ = new NothingHere("Texture")); nothing_.Visibility = System.Windows.Visibility.Visible; textureForm_.Visibility = System.Windows.Visibility.Collapsed; }
void UpdateAdditionalColumns() { GridView gridView = _treeList.View as GridView; EmployeesViewModel employeesViewModel = _treeList.DataContext as EmployeesViewModel; if (employeesViewModel.AdditionalColumnNames == null) return; var columnCount = 2; for (int i = gridView.Columns.Count - 1; i >= columnCount; i--) { gridView.Columns.RemoveAt(i); } for (int i = 0; i < employeesViewModel.AdditionalColumnNames.Count; i++) { var gridViewColumn = new GridViewColumn(); gridViewColumn.Header = employeesViewModel.AdditionalColumnNames[i]; gridViewColumn.Width = 350; var dataTemplate = new DataTemplate(); var txtElement = new FrameworkElementFactory(typeof(TextBlock)); dataTemplate.VisualTree = txtElement; var binding = new Binding(); var bindingPath = string.Format("AdditionalColumnValues[{0}]", i); binding.Path = new PropertyPath(bindingPath); binding.Mode = BindingMode.OneWay; txtElement.SetBinding(TextBlock.TextProperty, binding); ListViewLayoutManager.SetStarWidth(gridViewColumn, 5); gridViewColumn.CellTemplate = dataTemplate; gridView.Columns.Add(gridViewColumn); } }
public MainWindowViewModel() { SampleData.Seed(); // create accent color menu items for the demo this.AccentColors = ThemeManager.Accents .Select(a => new AccentColorMenuData() { Name = a.Name, ColorBrush = a.Resources["AccentColorBrush"] as Brush }) .ToList(); // create metro theme color menu items for the demo this.AppThemes = ThemeManager.AppThemes .Select(a => new AppThemeMenuData() { Name = a.Name, BorderColorBrush = a.Resources["BlackColorBrush"] as Brush, ColorBrush = a.Resources["WhiteColorBrush"] as Brush }) .ToList(); Albums = SampleData.Albums; Artists = SampleData.Artists; FlipViewTemplateSelector = new RandomDataTemplateSelector(); FrameworkElementFactory spFactory = new FrameworkElementFactory(typeof(Image)); spFactory.SetBinding(Image.SourceProperty, new System.Windows.Data.Binding(".")); spFactory.SetValue(Image.HorizontalAlignmentProperty, HorizontalAlignment.Stretch); spFactory.SetValue(Image.StretchProperty, Stretch.Fill); FlipViewTemplateSelector.TemplateOne = new DataTemplate() { VisualTree = spFactory }; FlipViewImages = new string[] { "http://trinities.org/blog/wp-content/uploads/red-ball.jpg", "http://savingwithsisters.files.wordpress.com/2012/05/ball.gif" }; RaisePropertyChanged("FlipViewTemplateSelector"); BrushResources = FindBrushResources(); }
internal static System.Windows.DataTemplate CreateCellTemplate(EntityFieldInfo entityFieldInfo,DataGrid dataGrid) { DataTemplate dataTemplate = new DataTemplate(); FrameworkElementFactory contentControl = new FrameworkElementFactory(typeof(ContentControl)); contentControl.SetBinding(ContentControl.ContentProperty, new Binding()); Style contentControlStyle = new Style(); contentControl.SetValue(ContentControl.StyleProperty, contentControlStyle); DataTemplate tpl = new DataTemplate(); if (entityFieldInfo.ControlType == Infrastructure.Attributes.ControlType.Color) { FrameworkElementFactory grid = new FrameworkElementFactory(typeof(Grid)); Binding binding = CreateBindingOneWay(entityFieldInfo.Path); binding.Converter = new StringToBrushConverter(); grid.SetBinding(Grid.BackgroundProperty, binding); tpl.VisualTree = grid; contentControlStyle.Setters.Add(new Setter(ContentControl.ContentTemplateProperty, tpl)); dataTemplate.VisualTree = contentControl; } else { FrameworkElementFactory textBox = new FrameworkElementFactory(typeof(TextBlock)); if (entityFieldInfo.ControlType == Infrastructure.Attributes.ControlType.Pr) { textBox.SetValue(TextBlock.TextAlignmentProperty, TextAlignment.Right); } textBox.SetBinding(TextBlock.TextProperty, CreateBindingOneWay(entityFieldInfo.Path)); tpl.VisualTree = textBox; contentControlStyle.Setters.Add(new Setter(ContentControl.ContentTemplateProperty, tpl)); dataTemplate.VisualTree = contentControl; } return dataTemplate; }
static DocUIDataGrid() { ColDict = new Dictionary<string, GetColumn>(); ColDict.Add("string", (Binding b) => { DataGridTextColumn col = new DataGridTextColumn(); col.Binding = b; col.Width = new DataGridLength(1, DataGridLengthUnitType.Star); return col; }); ColDict.Add("combobox", (Binding b) => { DataTemplate dt = new DataTemplate(); FrameworkElementFactory templatecheckbox = new FrameworkElementFactory(typeof(ComboBox)); templatecheckbox.SetBinding(ComboBox.TextProperty, b); dt.VisualTree = templatecheckbox; DataGridTemplateColumn col = new DataGridTemplateColumn(); col.CanUserResize = false; col.CellTemplate = dt; return col; }); }
private void GenerateMetaColumns() { while (_gridView.Columns.Count > 1) { _gridView.Columns.RemoveAt(1); } // dynamically generate columns for meta data var container = theView.DataContext as ContainerVM; if (container != null) { foreach (var info in container.KnownMetaData) { GridViewColumn col = new GridViewColumn { Header = info.Name, HeaderContainerStyle = TryFindResource(string.Format("{0}AlignColHeader", info.HeaderAlignment)) as Style, Width = info.Width, }; var txt = new FrameworkElementFactory(typeof(TextBlock)); txt.SetBinding(TextBlock.TextProperty, new Binding(string.Format("MetaData[{0}].Value", info.Name)) { Converter = info.Formatter, ConverterParameter = info.FormatParameter }); txt.SetValue(TextBlock.TextTrimmingProperty, TextTrimming.CharacterEllipsis); txt.SetValue(TextBlock.TextAlignmentProperty, info.ContentAlignment); col.CellTemplate = new DataTemplate() { VisualTree = txt }; _gridView.Columns.Add(col); } } }
public ListColorsEvenElegantlier() { Title = "List Colors Even Elegantlier"; DataTemplate template = new DataTemplate(typeof(NamedBrush)); FrameworkElementFactory factoryStack = new FrameworkElementFactory(typeof(StackPanel)); factoryStack.SetValue(StackPanel.OrientationProperty, Orientation.Horizontal); template.VisualTree = factoryStack; FrameworkElementFactory factoryRectangle = new FrameworkElementFactory(typeof(Rectangle)); factoryRectangle.SetValue(Rectangle.WidthProperty, 16.0); factoryRectangle.SetValue(Rectangle.HeightProperty, 16.0); factoryRectangle.SetValue(Rectangle.MarginProperty, new Thickness(2)); factoryRectangle.SetValue(Rectangle.StrokeProperty, SystemColors.WindowTextBrush); factoryRectangle.SetBinding(Rectangle.FillProperty, new Binding("Brush")); factoryStack.AppendChild(factoryRectangle); FrameworkElementFactory factoryTextBlock = new FrameworkElementFactory(typeof(TextBlock)); factoryTextBlock.SetValue(TextBlock.VerticalAlignmentProperty, VerticalAlignment.Center); factoryTextBlock.SetValue(TextBlock.TextProperty, new Binding("Name")); factoryStack.AppendChild(factoryTextBlock); ListBox lstbox = new ListBox(); lstbox.Width = 150; lstbox.Height = 150; Content = lstbox; lstbox.ItemTemplate = template; lstbox.ItemsSource = NamedBrush.All; lstbox.SelectedValuePath = "Brush"; lstbox.SetBinding(ListBox.SelectedValueProperty, "Background"); lstbox.DataContext = this; }
public static sw.FrameworkElementFactory TextBlock() { var factory = new sw.FrameworkElementFactory(typeof(swc.TextBlock)); factory.SetBinding(swc.TextBlock.TextProperty, new sw.Data.Binding { Path = TextPath }); factory.SetValue(swc.TextBlock.MarginProperty, new sw.Thickness(2)); return factory; }
public ColorWheel() { // Define the ItemsPanel template. FrameworkElementFactory factoryRadialPanel = new FrameworkElementFactory(typeof(RadialPanel)); ItemsPanel = new ItemsPanelTemplate(factoryRadialPanel); // Create the DataTemplate for the items. DataTemplate template = new DataTemplate(typeof(Brush)); ItemTemplate = template; // Create a FrameworkElementFactory based on Rectangle. FrameworkElementFactory elRectangle = new FrameworkElementFactory(typeof(Rectangle)); elRectangle.SetValue(Rectangle.WidthProperty, 4.0); elRectangle.SetValue(Rectangle.HeightProperty, 12.0); elRectangle.SetValue(Rectangle.MarginProperty, new Thickness(1, 8, 1, 8)); elRectangle.SetBinding(Rectangle.FillProperty, new Binding("")); // Use that factory for the visual tree. template.VisualTree = elRectangle; // Set the items in the ListBox. PropertyInfo[] props = typeof(Brushes).GetProperties(); foreach (PropertyInfo prop in props) Items.Add((Brush)prop.GetValue(null, null)); }
public static void ApplyAutogeneratedColumnAttributes(DataGridAutoGeneratingColumnEventArgs e) { PropertyDescriptor pd = e.PropertyDescriptor as PropertyDescriptor; if (pd.Attributes[typeof(HiddenColumn)] != null) { e.Cancel = true; return; } DisplayNameAttribute nameAttribute = pd.Attributes[typeof(DisplayNameAttribute)] as DisplayNameAttribute; if (nameAttribute != null && !String.IsNullOrEmpty(nameAttribute.DisplayName)) { e.Column.Header = nameAttribute.DisplayName; } ColumnWidth columnWidth = pd.Attributes[typeof(ColumnWidth)] as ColumnWidth; if (columnWidth != null) { e.Column.Width = columnWidth.Width; } if (e.PropertyType == typeof(double)) { (e.Column as DataGridTextColumn).Binding.StringFormat = "{0:0.###}"; } if (e.PropertyType == typeof(bool) && !e.Column.IsReadOnly) { var checkboxFactory = new FrameworkElementFactory(typeof(CheckBox)); checkboxFactory.SetValue(FrameworkElement.HorizontalAlignmentProperty, HorizontalAlignment.Center); checkboxFactory.SetValue(FrameworkElement.VerticalAlignmentProperty, VerticalAlignment.Center); checkboxFactory.SetBinding(CheckBox.IsCheckedProperty, new Binding(e.PropertyName) { UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged }); e.Column = new DataGridTemplateColumn { Header = e.Column.Header, CellTemplate = new DataTemplate { VisualTree = checkboxFactory }, SortMemberPath = e.Column.SortMemberPath }; } }
public EditableTextBlock() { var textBox = new FrameworkElementFactory(typeof(TextBox)); textBox.SetValue(Control.PaddingProperty, new Thickness(1)); // 1px for border textBox.AddHandler(FrameworkElement.LoadedEvent, new RoutedEventHandler(TextBox_Loaded)); textBox.AddHandler(UIElement.KeyDownEvent, new KeyEventHandler(TextBox_KeyDown)); textBox.AddHandler(UIElement.LostFocusEvent, new RoutedEventHandler(TextBox_LostFocus)); textBox.SetBinding(TextBox.TextProperty, new System.Windows.Data.Binding("Text") { Source = this, Mode = BindingMode.TwoWay, UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged }); var editTemplate = new DataTemplate { VisualTree = textBox }; var textBlock = new FrameworkElementFactory(typeof(TextBlock)); textBlock.SetValue(FrameworkElement.MarginProperty, new Thickness(2)); textBlock.AddHandler(UIElement.MouseDownEvent, new MouseButtonEventHandler(TextBlock_MouseDown)); textBlock.SetBinding(TextBlock.TextProperty, new System.Windows.Data.Binding("Text") { Source = this }); var viewTemplate = new DataTemplate { VisualTree = textBlock }; var style = new System.Windows.Style(typeof(EditableTextBlock)); var trigger = new Trigger { Property = IsInEditModeProperty, Value = true }; trigger.Setters.Add(new Setter { Property = ContentTemplateProperty, Value = editTemplate }); style.Triggers.Add(trigger); trigger = new Trigger { Property = IsInEditModeProperty, Value = false }; trigger.Setters.Add(new Setter { Property = ContentTemplateProperty, Value = viewTemplate }); style.Triggers.Add(trigger); Style = style; }
public override DataTemplate SelectTemplate(object item, DependencyObject container) { var row = item as RowViewModel; if (row == null) return null; bool isCondition = row.Header is ConditionViewModel; bool isAction = row.Header is ActionViewModel; IEnumerable<DependencyObject> cellPanelRoute = TreeHelper.GetRouteToAncestor<DataGridCellsPanel>(container); if (cellPanelRoute.Count() < 2) return null; DataGridCellsPanel cellPanel = cellPanelRoute.ElementAt(0) as DataGridCellsPanel; DataGridCell currentCell = cellPanelRoute.ElementAt(1) as DataGridCell; //First item is name of the condition/action, so minus 1 int ruleIndex = cellPanel.Children.IndexOf(currentCell) - 1; if (isCondition) { FrameworkElementFactory conditionFactory = new FrameworkElementFactory(typeof(DTCellComboBox)); conditionFactory.SetValue(DTCellComboBox.DisplayMemberPathProperty, "Name"); conditionFactory.SetBinding(DTCellComboBox.ItemsSourceProperty, new Binding("Header.ValidStatesWithEmptyState")); Binding selectedItemBinding = new Binding(string.Format("States[{0}]", ruleIndex)) { UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged, Mode = BindingMode.TwoWay }; conditionFactory.SetBinding(ComboBox.SelectedItemProperty, selectedItemBinding); return new DataTemplate { VisualTree = conditionFactory }; } else if (isAction) { FrameworkElementFactory actionFactory = new FrameworkElementFactory(typeof(DTCellComboBox)); actionFactory.SetValue(DTCellComboBox.DisplayMemberPathProperty, "Name"); actionFactory.SetBinding(DTCellComboBox.ItemsSourceProperty, new Binding("Header.ValidStatesWithEmptyState")); Binding selectedItemBinding = new Binding(string.Format("States[{0}]", ruleIndex)) { UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged, Mode = BindingMode.TwoWay }; actionFactory.SetBinding(ComboBox.SelectedItemProperty, selectedItemBinding); return new DataTemplate { VisualTree = actionFactory }; } return null; }
private DataTemplate BuildDataTemplate(Type viewModelType) { if (viewModelType == null) { throw new ArgumentNullException("viewModelType"); } const int standardMargin = 2; var defaultMargin = new Thickness(standardMargin); var allProperties = viewModelType.GetProperties().ToList(); var commandProperties = allProperties.Where(pi => pi.PropertyType.IsAssignableTo<ICommand>()).ToList(); var scalarProperties = allProperties.Where(pi => !pi.PropertyType.IsAssignableFrom<ICommand>()).ToList(); var elementFactory = new FrameworkElementFactory(typeof (StackPanel)); foreach (var scalarProperty in scalarProperties) { var textLineFactory = new FrameworkElementFactory(typeof (StackPanel)); textLineFactory.SetValue(StackPanel.OrientationProperty, Orientation.Horizontal); string name = scalarProperty.Name; //stackpanel for each scalar property contains of 2 textblocks - one for caption, one for value var captionTextBlockFactory = new FrameworkElementFactory(typeof(TextBlock)); captionTextBlockFactory.SetValue(TextBlock.TextProperty, name + ":"); captionTextBlockFactory.SetValue(FrameworkElement.MarginProperty, defaultMargin); textLineFactory.AppendChild(captionTextBlockFactory); var valueTextBlockFactory = new FrameworkElementFactory(typeof(TextBlock)); valueTextBlockFactory.SetBinding(TextBlock.TextProperty, new Binding(name)); valueTextBlockFactory.SetValue(FrameworkElement.MarginProperty, defaultMargin); textLineFactory.AppendChild(valueTextBlockFactory); elementFactory.AppendChild(textLineFactory); } //Create all buttons for commands if (commandProperties.Any()) { var buttonPanelFactory = new FrameworkElementFactory(typeof(StackPanel)); buttonPanelFactory.SetValue(StackPanel.OrientationProperty, Orientation.Vertical); foreach (var commandProperty in commandProperties) { var controlElementFactory = new FrameworkElementFactory(typeof(Button)); controlElementFactory.SetBinding(ButtonBase.CommandProperty, new Binding(commandProperty.Name)); controlElementFactory.SetValue(ContentControl.ContentProperty, commandProperty.Name); buttonPanelFactory.AppendChild(controlElementFactory); } elementFactory.AppendChild(buttonPanelFactory); } return new DataTemplate { DataType = viewModelType, VisualTree = elementFactory }; }
public static sw.FrameworkElementFactory TextBlock() { var factory = new sw.FrameworkElementFactory(typeof(swc.TextBlock)); factory.SetBinding(swc.TextBlock.TextProperty, new sw.Data.Binding { Converter = new TextConverter() }); return(factory); }
public ListColorsEvenElegantlier() { Title = "List Colors Even Elegantlier"; // Create a DataTemplate for the items. DataTemplate template = new DataTemplate(typeof(NamedBrush)); // Create a FrameworkElementFactory based on StackPanel. FrameworkElementFactory factoryStack = new FrameworkElementFactory(typeof(StackPanel)); factoryStack.SetValue(StackPanel.OrientationProperty, Orientation.Horizontal); // Make that the root of the DataTemplate visual tree. template.VisualTree = factoryStack; // Create a FrameworkElementFactory based on Rectangle. FrameworkElementFactory factoryRectangle = new FrameworkElementFactory(typeof(Rectangle)); factoryRectangle.SetValue(Rectangle.WidthProperty, 16.0); factoryRectangle.SetValue(Rectangle.HeightProperty, 16.0); factoryRectangle.SetValue(Rectangle.MarginProperty, new Thickness(2)); factoryRectangle.SetValue(Rectangle.StrokeProperty, SystemColors.WindowTextBrush); factoryRectangle.SetBinding(Rectangle.FillProperty, new Binding("Brush")); // Add it to the StackPanel. factoryStack.AppendChild(factoryRectangle); // Create a FrameworkElementFactory based on TextBlock. FrameworkElementFactory factoryTextBlock = new FrameworkElementFactory(typeof(TextBlock)); factoryTextBlock.SetValue(TextBlock.VerticalAlignmentProperty, VerticalAlignment.Center); factoryTextBlock.SetValue(TextBlock.TextProperty, new Binding("Name")); // Add it to the StackPanel. factoryStack.AppendChild(factoryTextBlock); // Create ListBox as content of window. ListBox lstbox = new ListBox(); lstbox.Width = 150; lstbox.Height = 150; Content = lstbox; // Set the ItemTemplate property to the template created above. lstbox.ItemTemplate = template; // Set the ItemsSource to the array of NamedBrush objects. lstbox.ItemsSource = NamedBrush.All; // Bind the SelectedValue to window Background. lstbox.SelectedValuePath = "Brush"; lstbox.SetBinding(ListBox.SelectedValueProperty, "Background"); lstbox.DataContext = this; }
private static GridViewColumn CreateColumn(EntityCustomField customField) { var template = new DataTemplate { DataType = typeof(string) }; var fef = new FrameworkElementFactory(typeof(TextBlock)); fef.SetBinding(TextBlock.TextProperty, new Binding("[" + customField.Name + "]") { StringFormat = customField.EditingFormat }); template.VisualTree = fef; var c = new GridViewColumn { Header = customField.Name, CellTemplate = template }; ProportionalColumn.ApplyWidth(c, 1); return c; }
public static sw.FrameworkElementFactory EditableBlock(swd.RelativeSource relativeSource) { var factory = new sw.FrameworkElementFactory(typeof(EditableTextBlock)); var binding = new sw.Data.Binding { Path = new sw.PropertyPath("Text"), RelativeSource = relativeSource, Mode = swd.BindingMode.TwoWay, UpdateSourceTrigger = swd.UpdateSourceTrigger.LostFocus }; factory.SetBinding(EditableTextBlock.TextProperty, binding); return(factory); }
public static sw.FrameworkElementFactory ImageBlock() { var factory = new sw.FrameworkElementFactory(typeof(swc.Image)); factory.SetValue(swc.Image.MaxHeightProperty, 16.0); factory.SetValue(swc.Image.MaxWidthProperty, 16.0); factory.SetValue(swc.Image.StretchDirectionProperty, swc.StretchDirection.DownOnly); factory.SetValue(swc.Image.MarginProperty, new sw.Thickness(0, 2, 2, 2)); factory.SetBinding(swc.Image.SourceProperty, new sw.Data.Binding { Converter = new ImageConverter() }); return factory; }
public static sw.FrameworkElementFactory TextBlock() { var factory = new sw.FrameworkElementFactory(typeof(swc.TextBlock)); factory.SetBinding(swc.TextBlock.TextProperty, new sw.Data.Binding { Path = TextPath }); factory.SetValue(swc.TextBlock.MarginProperty, new sw.Thickness(2)); return(factory); }
public static sw.FrameworkElementFactory ImageBlock() { var factory = new sw.FrameworkElementFactory(typeof(swc.Image)); factory.SetValue(sw.FrameworkElement.MaxHeightProperty, 16.0); factory.SetValue(sw.FrameworkElement.MaxWidthProperty, 16.0); factory.SetValue(swc.Image.StretchDirectionProperty, swc.StretchDirection.DownOnly); factory.SetValue(sw.FrameworkElement.MarginProperty, new sw.Thickness(0, 2, 2, 2)); factory.SetBinding(swc.Image.SourceProperty, new sw.Data.Binding { Converter = new ImageConverter() }); return(factory); }
public static sw.FrameworkElementFactory TextBlock(bool setMargin = true) { var factory = new sw.FrameworkElementFactory(typeof(swc.TextBlock)); factory.SetBinding(swc.TextBlock.TextProperty, new sw.Data.Binding { Path = new sw.PropertyPath("Text") }); if (setMargin) { factory.SetValue(sw.FrameworkElement.MarginProperty, new sw.Thickness(2)); } return(factory); }
private void AddRatingColumn(string header, int width, string bindingPath) { DataGridTemplateColumn nc = new DataGridTemplateColumn(); System.Windows.DataTemplate template = new System.Windows.DataTemplate(); System.Windows.FrameworkElementFactory factoryRatingControl = new System.Windows.FrameworkElementFactory(typeof(RatingUserControl)); System.Windows.Data.Binding binding = new System.Windows.Data.Binding(bindingPath); //binding.Converter = new Int32Converter(); factoryRatingControl.SetBinding(RatingUserControl.RatingProperty, binding); factoryRatingControl.SetValue(RatingUserControl.HorizontalAlignmentProperty, System.Windows.HorizontalAlignment.Left); factoryRatingControl.SetValue(RatingUserControl.ReadOnlyProperty, true); template.VisualTree = factoryRatingControl; nc.CellTemplate = template; nc.Header = header; nc.Width = width; nc.IsReadOnly = true; dataGrid.Columns.Add(nc); }
private DockPanel CreateUI() { DockPanel collision_dock_panel = new DockPanel() { LastChildFill = true }; StackPanel collision_stack_panel = new StackPanel() { HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch, VerticalAlignment = System.Windows.VerticalAlignment.Stretch, }; RowDefinition tree_row = new RowDefinition(); RowDefinition splitter_row = new RowDefinition(); RowDefinition properties_row = new RowDefinition(); tree_row.Height = System.Windows.GridLength.Auto; tree_row.MaxHeight = 500; tree_row.MinHeight = 10; splitter_row.Height = System.Windows.GridLength.Auto; properties_row.Height = System.Windows.GridLength.Auto; properties_row.MinHeight = 80; Grid col_grid = new Grid(); col_grid.RowDefinitions.Add(tree_row); col_grid.RowDefinitions.Add(splitter_row); col_grid.RowDefinitions.Add(properties_row); System.Windows.HierarchicalDataTemplate template = new System.Windows.HierarchicalDataTemplate(typeof(CollisionGroupNode)); template.ItemsSource = new Binding("Children"); System.Windows.FrameworkElementFactory tb = new System.Windows.FrameworkElementFactory(typeof(TextBlock)); tb.SetBinding(TextBlock.TextProperty, new Binding("Name")); tb.SetValue(TextBlock.ForegroundProperty, Brushes.Black); template.VisualTree = tb; m_CollisionTree = new TreeView() { VerticalAlignment = System.Windows.VerticalAlignment.Stretch, HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch, ItemTemplate = template }; m_CollisionTree.SelectedItemChanged += M_test_tree_SelectedItemChanged; m_CollisionTree.PreviewMouseLeftButtonDown += OnItemMouseDoubleClick; Grid.SetRow(m_CollisionTree, 0); GridSplitter splitter = new GridSplitter() { Height = 5, VerticalAlignment = System.Windows.VerticalAlignment.Top, HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch }; Grid.SetRow(splitter, 1); WDetailsView actor_details = new WDetailsView() { Name = "Details", HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch, VerticalAlignment = System.Windows.VerticalAlignment.Stretch, DataContext = DetailsViewModel }; GroupBox actor_prop_box = new GroupBox() { HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch, VerticalAlignment = System.Windows.VerticalAlignment.Stretch, Header = "Properties", Content = actor_details, }; Grid.SetRow(actor_prop_box, 2); col_grid.Children.Add(m_CollisionTree); col_grid.Children.Add(splitter); col_grid.Children.Add(actor_prop_box); DockPanel.SetDock(collision_stack_panel, Dock.Top); collision_stack_panel.Children.Add(col_grid); collision_dock_panel.Children.Add(collision_stack_panel); return(collision_dock_panel); }
private void CreateHeader(ColumnFieldCollection fields) { dataGrid.Columns.Clear(); //Int32Converter int32Conv = new Int32Converter(); int i = 0; foreach (ColumnField field in fields) { Type columnType = DataBase.GetTypeByField(field.Field); int width = field.Width; string columnName = DataBase.GetNameOfField(field.Field, false); switch (field.Field) { case Field.Rating: { DataGridRatingColumn nc = new DataGridRatingColumn(); System.Windows.DataTemplate template = new System.Windows.DataTemplate(); System.Windows.FrameworkElementFactory factoryRatingControl = new System.Windows.FrameworkElementFactory(typeof(RatingUserControl)); System.Windows.Data.Binding binding = new System.Windows.Data.Binding("Items[" + i + "]"); binding.Mode = BindingMode.TwoWay; //binding.Converter = int32Conv; factoryRatingControl.SetBinding(RatingUserControl.RatingProperty, binding); factoryRatingControl.SetValue(RatingUserControl.HorizontalAlignmentProperty, System.Windows.HorizontalAlignment.Left); factoryRatingControl.AddHandler(RatingUserControl.MouseLeftButtonDownEvent, new MouseButtonEventHandler(RatingCell_MouseLeftButtonDown)); nc.SetValue(DataGridExtensions.FieldProperty, field.Field); //factoryRatingControl.SetValue(RatingUserControl.ReadOnlyProperty, true); template.VisualTree = factoryRatingControl; nc.CanUserSort = true; nc.CellTemplate = template; //nc.CellEditingTemplate = template; nc.Header = columnName; nc.Width = width; // Auf Read-Only setzen, da wir das manuell machen (im MouseLeftButtonDown) nc.IsReadOnly = true; nc.SortMemberPath = "Items[" + i + "]"; dataGrid.Columns.Add(nc); break; } case Field.Comment: { DataGridTemplateColumn newMultilineColumn = new DataGridTemplateColumn(); newMultilineColumn.Width = field.Width; newMultilineColumn.Header = DataBase.GetNameOfField(field.Field); newMultilineColumn.SetValue(DataGridExtensions.FieldProperty, field.Field); DataTemplate multilineCelltemplate = this.FindResource("CommentTemplate") as DataTemplate; newMultilineColumn.CellTemplate = multilineCelltemplate; newMultilineColumn.CellEditingTemplate = multilineCelltemplate; dataGrid.Columns.Add(newMultilineColumn); break; } default: { DataGridMaxLengthTextColumn nc = new DataGridMaxLengthTextColumn(); nc.SetValue(DataGridExtensions.FieldProperty, field.Field); System.Windows.Data.Binding binding = new System.Windows.Data.Binding("Items[" + i + "]"); if (field.Field == Field.TotalLength) { binding.Converter = new Big3.Hitbase.Miscellaneous.LengthConverter(); } else if (field.Field == Field.Price) { binding.Converter = new PriceConverter(); } else if (field.Field == Field.Date) { binding.Converter = new DataBaseDateConverter(); binding.ConverterParameter = this.DataBase; } else if (field.Field == Field.AlbumType) { binding.Converter = new AlbumTypeConverter(); nc.IsReadOnly = true; } else if (IsUserFieldDateFormat(field.Field)) { binding.Converter = new UserFieldDateConverter(); } else if (DataBase.GetTypeByField(field.Field) == typeof(int)) { binding.Converter = new MyInt32Converter(); } else if (DataBase.GetTypeByField(field.Field) == typeof(bool)) { binding.Converter = new BoolConverter(); } nc.Binding = binding; nc.Header = columnName; nc.Width = width; if (DataBase.GetTypeByField(field.Field) == typeof(string)) { nc.MaxLength = DataBase.GetMaxStringLength(field.Field); } //nc.IsReadOnly = true; dataGrid.Columns.Add(nc); break; } } i++; } CurrentFields = fields; }