2 czf2505 czf2505 于 2014.01.14 18:50 提问

WPF怎么在后台设置 FrameworkElementFactory中的控件大小或者右对齐

Dim objTemColumn As New DataGridTemplateColumn
Dim objTem As New DataTemplate
Dim objFactory = New FrameworkElementFactory(GetType(StackPanel))
objFactory.Name = "myFactory"
objFactory.SetValue(StackPanel.OrientationProperty, Orientation.Horizontal)
Dim myTextBlock As New FrameworkElementFactory(GetType(TextBlock))
myTextBlock.SetBinding(TextBlock.TextProperty, New Binding(strName))

            myTextBlock.SetValue(TextBlock.ForegroundProperty, Brushes.Orange)




            objFactory.AppendChild(myTextBlock)
            Dim myImage As New FrameworkElementFactory(GetType(Image))
            myImage.SetBinding(Image.SourceProperty, New Binding(strName + "_Img"))
            myImage.SetValue(Image.HorizontalAlignmentProperty, Windows.HorizontalAlignment.Right)
            objFactory.AppendChild(myImage)
            objTem.VisualTree = objFactory
            objTemColumn.CellTemplate = objTem
            objTemColumn.Header = strName + "_Diff"
            objTemColumn.Width = 50
            myGrid.Columns.Add(objTemColumn)

1 问题1 myImage.SetValue(Image.HorizontalAlignmentProperty, Windows.HorizontalAlignment.Right)
这句代码没有起到设置控件里面内容的对齐方式
2 问题2 假如我想设置 myImage这个控件宽度,可以做到吗,我直接给属性赋值
myImage.SetValue(Image.WidthProperty, 60)
系统无法识别60是一个对象

1个回答

chuwh
chuwh   2016.06.14 15:46

myImage.SetValue(Image.WidthProperty, 60.00)

Csdn user default icon
上传中...
上传图片
插入图片