frameworkelementfactory

Create a grid in WPF as Template programmatically

醉酒当歌 提交于 2019-12-01 16:24:34
I want to create a basic user control with a style programmatically. In this style I want to add a Grid (no problem), but I can't add column definitions to this grid. My example code is 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);

Create a grid in WPF as Template programmatically

心已入冬 提交于 2019-12-01 14:20:02
问题 I want to create a basic user control with a style programmatically. In this style I want to add a Grid (no problem), but I can't add column definitions to this grid. My example code is ControlTemplate templ = new ControlTemplate(); FrameworkElementFactory mainPanel = new FrameworkElementFactory(typeof(DockPanel)); mainPanel.SetValue(DockPanel.LastChildFillProperty, true); FrameworkElementFactory headerPanel = new FrameworkElementFactory(typeof(StackPanel)); headerPanel.SetValue(StackPanel

Purpose of using FrameworkElementFactory

荒凉一梦 提交于 2019-11-28 08:28:51
问题 In one of the application I am working I have found this code - public class MatrixCellTemplate : ColumnDataTemplate<MatrixCellContainer> { } public class ColumnDataTemplate<T> : DataTemplate where T : FrameworkElement { public ColumnDataTemplate() { FrameworkElementFactory factory = new FrameworkElementFactory(typeof(T)); VisualTree = factory; } } This MatrixCellTemplate is used to set the CellTemplate of a custom DataGridTemplateColumn (later added to DataGrid.Columns collection) like this

Converting ControlTemplate XAML to C#

吃可爱长大的小学妹 提交于 2019-11-28 05:06:00
问题 I have been stumped with trying to convert the following code into pure c#. This XAML code is from Cavanaghs blog on how to make rounded corners on anything. The code works but I need to convert it to c# as i need it to be dynamic in some cases. If you could help that would be great. <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType='{x:Type ListViewItem}'> <Grid> <Border CornerRadius="15" Name="mask" Background="White"/> <StackPanel Background="Beige"> <StackPanel