Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/visual-studio/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Wpf 如何以编程方式设置文本块';s Grid.Column属性_Wpf_F# - Fatal编程技术网

Wpf 如何以编程方式设置文本块';s Grid.Column属性

Wpf 如何以编程方式设置文本块';s Grid.Column属性,wpf,f#,Wpf,F#,所以我就跟着书走。我在第2章的第3个代码示例中。我一直在F#中使用无代码XAML重新创建它的内容 我需要设置TextBlock的Grid.Column属性。只有当我为我的文本块自动完成时,才发现没有网格属性,所以我研究了它,它被称为附加属性。我抬起头来 不幸的是,尽管知道这一点并遵循MSDN的示例,但我无法让它工作。我得到这个错误 1 is not a valid value for property 'Column' 如果1无效,我不确定它应该是什么。 VisualStudio中的Inte

所以我就跟着书走。我在第2章的第3个代码示例中。我一直在F#中使用无代码XAML重新创建它的内容

我需要设置TextBlock的Grid.Column属性。只有当我为我的文本块自动完成时,才发现没有网格属性,所以我研究了它,它被称为附加属性。我抬起头来

不幸的是,尽管知道这一点并遵循MSDN的示例,但我无法让它工作。我得到这个错误

 1 is not a valid value for property 'Column'
如果1无效,我不确定它应该是什么。 VisualStudio中的Intellisense告诉我 是一个对象,实际上没有用处

这是我的密码

type L3Display() as this =
   class
   inherit TextBlock()
   do
   this.Margin <- new Thickness(5.0,10.0,5.0,5.0)
   this.FontSize <- 14.0
   this.HorizontalAlignment <- HorizontalAlignment.Right
   this.SetValue(Grid.ColumnProperty, 1.0)
   this.TextAlignment <- TextAlignment.Center

   end
键入L3Display(),如下所示=
班
继承TextBlock()
做

此.Margin您需要将ColumnProperty设置为
integer
而不是
float

this.SetValue(Grid.ColumnProperty, 1)

是否要将文本块设置到网格中?下面的代码是用vb编写的,但我就是这样做的

Dim txt1 As New TextBlock()
txt1.HorizontalAlignment = Windows.HorizontalAlignment.Center
txt1.VerticalAlignment = Windows.VerticalAlignment.Center
txt1.Text = ""
contentGrid.Children.Add(txt1)
Grid.SetColumn(txt1, 0)
Grid.SetRow(txt1, 0)

contentGrid是在代码隐藏中动态创建的网格,这是我在更大代码中向网格添加控件的一部分。希望能有帮助。

我会试一试,WPF中的许多其他东西都是浮点数,而intellisense只是告诉我SetValue()的第二个参数是一个对象,这没有什么帮助。如果你要进行向下投票,那很好,但考虑到我曾经研究过这个问题,至少要留下一个解释。
Dim txt1 As New TextBlock()
txt1.HorizontalAlignment = Windows.HorizontalAlignment.Center
txt1.VerticalAlignment = Windows.VerticalAlignment.Center
txt1.Text = ""
contentGrid.Children.Add(txt1)
Grid.SetColumn(txt1, 0)
Grid.SetRow(txt1, 0)