Tag: frameworkelementfactory

以编程方式在WPF中创建网格作为模板

我想以编程方式创建一个带有样式的基本用户控件。 在这种风格中我想添加一个Grid (没问题),但是我不能在这个网格中添加列定义。 我的示例代码是 ControlTemplate templ = new ControlTemplate(); FrameworkElementFactory mainPanel = new FrameworkElementFactory(typeof(DockPanel)); mainPanel.SetValue(DockPanel.LastChildFillProperty, true); FrameworkElementFactory headerPanel = new FrameworkElementFactory(typeof(StackPanel)); headerPanel.SetValue(StackPanel.OrientationProperty, Orientation.Horizontal); headerPanel.SetValue(DockPanel.DockProperty, Dock.Top); mainPanel.AppendChild(headerPanel); FrameworkElementFactory headerImg = new FrameworkElementFactory(typeof(Image)); headerImg.SetValue(Image.MarginProperty, new Thickness(5)); headerImg.SetValue(Image.HeightProperty, 32d); headerImg.SetBinding(Image.SourceProperty, new Binding(“ElementImage”) { RelativeSource = new RelativeSource(RelativeSourceMode.TemplatedParent) }); headerPanel.AppendChild(headerImg); FrameworkElementFactory headerTitle = new FrameworkElementFactory(typeof(TextBlock)); headerTitle.SetValue(TextBlock.FontSizeProperty, 16d); headerTitle.SetValue(TextBlock.VerticalAlignmentProperty, VerticalAlignment.Center); […]

将ControlTemplate XAML转换为C#

我一直难以尝试将以下代码转换为纯c#。 这个XAML代码来自Cavanaghs博客,关于如何在任何东西上制作圆角。 代码可以工作但我需要将它转换为c#,因为在某些情况下我需要它是动态的。 如果你能提供帮助那就太好了。 到目前为止,我有以下但我得到错误。 FrameworkElementFactory border = new FrameworkElementFactory(typeof(Border)); border.SetValue(Border.BackgroundProperty, Brushes.White); border.SetValue(Border.CornerRadiusProperty, new CornerRadius(8, 8, 8, 8)); border.SetValue(Border.NameProperty, “roundedMask”); 据我所知,我不能将VisualBrush作为FrameworkElementFactory(崩溃),但如果我将它声明为常规元素VisualBrush,我不能将其作为VisualE传递边界,因为它是一个FrameworkElementFactory。 只是我迷路了,任何帮助将不胜感激。 谢谢你的帮助