gpt4 book ai didi

c# - 为什么我不能在 Silverlight 中绑定(bind) Grid.RowDefinition 高度?

转载 作者:太空狗 更新时间:2023-10-30 01:27:42 25 4
gpt4 key购买 nike

当我运行以下 Silverlight 应用程序时,出现错误:

AG_E_PARSER_BAD_PROPERTY_VALUE [Line: 12 Position: 35]

我在 WPF 中尝试了相同的代码并且它运行良好,即中间网格行根据绑定(bind)值正确调整大小。

我必须更改此代码中的哪些内容才能避免在 Silverlight 中出现此错误?

XAML:

<UserControl x:Class="TestRowHeight222.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" d:DesignWidth="640" d:DesignHeight="480">
<Grid x:Name="LayoutRoot">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="30"/>
<RowDefinition Height="{Binding ContentHeight}"/>
<RowDefinition Height="30"/>
</Grid.RowDefinitions>

<StackPanel Grid.Row="0" Background="Tan">
<TextBlock Text="row0" />
</StackPanel>

<StackPanel Grid.Row="1" Background="Beige" Orientation="Horizontal">
<TextBlock Text="The height should be: "/>
<TextBlock Text="{Binding ContentHeight}"/>
</StackPanel>

<StackPanel Grid.Row="2" Background="Tan">
<TextBlock Text="row2"/>
</StackPanel>
</Grid>
</UserControl>

代码隐藏:

using System.Windows.Controls;
using System.ComponentModel;

namespace TestRowHeight222
{
public partial class MainPage : UserControl, INotifyPropertyChanged
{
#region ViewModelProperty: ContentHeight
private int _contentHeight;
public int ContentHeight
{
get
{
return _contentHeight;
}

set
{
_contentHeight = value;
OnPropertyChanged("ContentHeight");
}
}
#endregion

public MainPage()
{
InitializeComponent();
DataContext = this;
ContentHeight = 50;
}

#region INotifiedProperty Block
public event PropertyChangedEventHandler PropertyChanged;

protected void OnPropertyChanged(string propertyName)
{
PropertyChangedEventHandler handler = PropertyChanged;

if (handler != null)
{
handler(this, new PropertyChangedEventArgs(propertyName));
}
}
#endregion
}
}

最佳答案

这是我能得到的最接近的,我不知道它是否适合你的情况。

<Grid x:Name="LayoutRoot">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="30"/>
<RowDefinition Height="Auto" />
<RowDefinition Height="30"/>
</Grid.RowDefinitions>

<StackPanel Grid.Row="0" Background="Tan">
<TextBlock Text="row0" />
</StackPanel>

<Grid Grid.Row="1" Height="{Binding ContentHeight}">
<StackPanel Background="Beige" Orientation="Horizontal">
<TextBlock Text="The height should be: "/>
<TextBlock Text="{Binding ContentHeight}"/>
</StackPanel>
</Grid>

<StackPanel Grid.Row="2" Background="Tan">
<TextBlock Text="row2"/>
</StackPanel>
</Grid>

同时将您的 ContentHeight 属性更改为 double 值。

关于c# - 为什么我不能在 Silverlight 中绑定(bind) Grid.RowDefinition 高度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2409439/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com