Hey Richard, I have retracted my previous answer and updated this new one, hopefully it makes more sense. Additionally please use the "comment" option if you would like more information about a proposed answer.
Basically I've just added a rectangle with a glow effect to a canvas and then bound the size of the halo to a property that I manipulate every time the mouse moves over the Canvas
.
Please note, for this to work your code behind class will need to implement the INotifyPropertyChanged
interface which is in the System.ComponentModel
namespace. You will also need to make sure the datacontext of the window is set correctly.
The content of my Window
XAML:
<Canvas Background="DarkGray"
MouseMove="Canvas_MouseMove">
<Rectangle Margin="40,40,0,0"
Width="200"
Height="200"
Fill="Gray"
Stroke="Black"
StrokeThickness="2">
<Rectangle.BitmapEffect>
<OuterGlowBitmapEffect GlowColor="Goldenrod"
GlowSize="{Binding Path=GlowSize}"/>
</Rectangle.BitmapEffect>
</Rectangle>
</Canvas>
</Window>
Code Behind for my Window:
public class Window1 : Window, INotifyPropertyChanged
{
private double m_glowSize;
public double GlowSize
{
get { return m_glowSize; }
set
{
m_glowSize = value;
NotifyPropertyChanged("GlowSize");
}
}
public Window1() //this is my class constructor
{
DataContext = this;
InitializeComponent();
}
private void Canvas_MouseMove(object sender, MouseEventArgs e)
{
Canvas canvas = sender as Canvas;
if (canvas != null)
{
Point mousePosition = e.GetPosition(canvas);
GlowSize = 20 * (mousePosition.X / canvas.ActualWidth);
}
}
private void NotifyPropertyChanged(string s)
{
if (PropertyChanged != null)
PropertyChanged(this, new PropertyChangedEventArgs(s));
}
}
As a very basic interpretation of DataContext, you can think of it as the object to which the bindings will seek their bound properties. In this instance we want to make sure that the bindings in our window's XAML are found in its code behind file.
Also, if you haven't already. Take a look at this
http://msdn.microsoft.com/en-us/library/aa970268.aspx
I found it very helpful when I first started
Hope it helps.