In the following Silverlight application why does the property OuterPadding not change the padding in the outer border, although the TextBlock correctly displays the value of OuterPadding? If I change the Border padding to a simple integer it the padding works fine, but not when it is defined by the property in code behind.
This same code works fine in WPF.
XAML:
<UserControl x:Class="Test222.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:pages="clr-namespace:Test222.Pages"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
Width="600" Height="480">
<Border Background="#eee" Padding="{Binding OuterPadding}">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="34"/>
<RowDefinition Height="426"/>
</Grid.RowDefinitions>
<StackPanel Grid.Row="0" Grid.Column="0">
<StackPanel x:Name="QuickMenu" Orientation="Horizontal"/>
</StackPanel>
<Border Grid.Row="1" Grid.Column="0"
Background="#fff"
Padding="10"
Width="580"
Height="426"
VerticalAlignment="Top"
CornerRadius="5">
<TextBlock Text="{Binding OuterPadding}"/>
</Border>
</Grid>
</Border>
</UserControl>
Code Behind:
using System.ComponentModel;
using System.Windows;
using System.Windows.Controls;
namespace Test222
{
public partial class MainPage : UserControl, INotifyPropertyChanged
{
#region ViewModelProperty: OuterPadding
private int _outerPadding;
public int OuterPadding
{
get
{
return _outerPadding;
}
set
{
_outerPadding = value;
OnPropertyChanged("OuterPadding");
}
}
#endregion
public MainPage()
{
InitializeComponent();
DataContext = this;
RefreshApplication();
}
void RefreshApplication()
{
OuterPadding = 5;
for (int i = 0; i < 5; i++)
{
var button = new Button();
button.Content = "Button " + i;
button.Margin = new Thickness { Right = 3 };
QuickMenu.Children.Add(button);
}
}
#region INotifyPropertyChanged Member
public event PropertyChangedEventHandler PropertyChanged;
protected void OnPropertyChanged(string propertyName)
{
PropertyChangedEventHandler handler = PropertyChanged;
if (handler != null)
{
handler(this, new PropertyChangedEventArgs(propertyName));
}
}
#endregion
}
}