Hello!
I'm using WPF within Visual Studio 2008. I have a simple WPF UserControl with the following code:
public partial class UserControl1 : UserControl
{
public UserControl1()
{
InitializeComponent();
Composite = new Composite();
}
protected override void OnRender(DrawingContext drawingContext)
{
//LayoutRoot is name of default Grid instance
if (!LayoutRoot.Children.Contains(Composite))
{
LayoutRoot.Children.Add(Composite);
}
}
public Composite Composite
{
get;
set;
}
}
public class Composite : ContentControl
{
protected override void OnRender(DrawingContext drawingContext)
{
drawingContext.DrawRectangle(new SolidColorBrush(Color), new Pen(Brushes.Black, 1.0), new Rect(RenderSize));
}
public Color Color
{
get;
set;
}
}
I then use this UserControl in a WPF application, the XAML of the page looking like this:
<Window x:Class="WpfApplication1.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:test="clr-namespace:WpfControlLibrary1;assembly=WpfControlLibrary1"
Title="Window1" Height="500" Width="700" Background="AliceBlue">
<test:UserControl1 Name="uControl1">
<test:UserControl1.Composite>
<test:Composite Color="Green"/>
</test:UserControl1.Composite>
</test:UserControl1>
</Window>
My question is: what code do I have to add to the above so that by changing "Composite Color" to something other than Green and hitting the return button, the UserControl automatically refreshes? The behaviour I'm looking for is what happens when you change the Background of Window1 to a color other than AliceBlue and hit return.
When I run the code the correct color is seen, the problem is with the refresh at designtime via XAML.
Many thanks for any pointers which help me understand what is going on here!