views:

440

answers:

1

When I run the following Silverlight app, it gives me the error:

AG_E_PARSER_BAD_PROPERTY_VALUE [Line: 12 Position: 35]

I've tried the same code in WPF and it runs fine, i.e. the middle grid row correctly resizes based on the bound value.

What do I have to change in this code to avoid this error in 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>

Code Behind:

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
    }
}
+2  A: 

This is as close as I can get, I don't know if it's suitable to your situation.

<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>

Also change your ContentHeight property to a double.

Dan Wray
even if I change my ContentHeight ViewModelProperty from int to GridLength and then define it as ContentHeight = new GridLength(100, GridUnitType.Pixel); it gives me the same error
Edward Tanguay
My apologies, not as straightforward as it first seemed to me. I had a go myself also and couldn't get it to work.Last post in this thread appears to explain why : http://forums.silverlight.net/forums/t/95363.aspx
Dan Wray
I suspected that this is just not possible, I wonder if there is some creative workaround though
Edward Tanguay
see edited answer above, that's my stab at it. Doing it like this has an obvious drawback or two, so I don't know if it's suitable in this instance.
Dan Wray
yes, that works in my case, thanks for the idea
Edward Tanguay