Quand je lance l'application Silverlight suivante, il me donne l'erreur :Pourquoi ne puis-je pas lier la hauteur Grid.RowDefinition dans Silverlight?
AG_E_PARSER_BAD_PROPERTY_VALUE [Ligne: 12 Position: 35]
J'ai essayé le même code dans WPF et il exécute fine, c'est-à-dire la ligne de la grille du milieu se redimensionne correctement en fonction de la valeur liée.
Que dois-je modifier dans ce code pour éviter cette erreur dans 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 Derrière:
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
}
}
même si je change ContentHeight ViewModelProperty de int à GridLength et que je le définis comme ContentHeight = new GridLength (100, GridUnitType.Pixel); ça me donne la même erreur –
Mes excuses, pas aussi simple que cela me semblait. J'y suis allé aussi et je ne pouvais pas le faire fonctionner. Dernier message dans ce fil semble expliquer pourquoi: http://forums.silverlight.net/forums/t/95363.aspx –
Je me doutais que ce n'est tout simplement pas possible, je me demande s'il existe une solution de rechange créative si –