c# - 如何从 Double 转换为 GridLength? C#

标签 c# xaml stackpanel

我正在尝试获取 GridRow[0] 及其父级 (Stackpanel) 的值,然后我从 Stackpanel 值中减去 GridRow[0] 的值。 我的最后一步是将结果分配给 GridRow[1]。

gridLengthVariable  = othergridLengthVariable - doubleVariable;

在这种情况下,我无法进行从 Double 到 GridLength 的显式转换

gridLengthVariable.Value

是一个只读属性,所以我不能在这里分配。

我需要一种将 double 转换为 gridLength 的方法,但如果这能给我带来相同的解决方案,我愿意对我的代码进行更深入的更改。

无法完成 XAML 更改。

编辑:

我将展示我正在尝试做的事情:

它是 XAML 创建的 gridRow 的动态变化。

     gridProfile.RowDefinitions[1].Height =  
     stackPanelProfile.Height -  gridProfile.RowDefinitions[0].Height;

这里我不能应用运算符“-

谢谢。

最佳答案

GridLength是一个结构。它不仅仅是一个 double 值。例如,它也可以是 Auto

您可以创建一个新的 GridLength 并通过构造函数提供实际值:

gridLengthVariable = new GridLength(othergridLengthVariable - doubleVariable);

关于c# - 如何从 Double 转换为 GridLength? C#,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47530320/

相关文章:

xaml - Xamarin.Forms:有没有办法在 xaml 的派生样式中设置默认字体(系列)?

c# - Microsoft.Bot.Builder.dll ("Access Denied"中的 Microsoft.Rest.HttpOperationException)在测试 PromptDialog.Confirm 时

c# - 为什么 Xamarin.Form XAML 文件中 StackLayout 的子元素超出屏幕范围?

c# - WPF - 在 Extended WPF Toolkit 中自定义 MessageBox 的样式

wpf - 在 WPF 中的堆栈面板中对齐左侧和右侧的控件

WPF:在不可变对象(immutable对象)实例上返回 "Cannot animate ' Color' 样式的 Storyboard。”

wpf - 水平堆叠面板中有两行? (WPF)

c# - 如何获取通过 SSRS 生成的 pdf 字节数组的页数

C# .NET 生成一次字符串数组,其索引是表中的字符串值

c# - "The subprocess making the call can not access this object because the owner is another thread"异常异步/等待 WPF C#