- legionvs2008silverlight2rtm.zip
- Documentation
- Libraries
- Clog
- Orpius.Logging.dll
- Orpius.Logging.Log4NetLogStrategy.dll
- Orpius.Logging.Log4NetLogStrategy.pdb
- Orpius.Logging.pdb
- Silverlight
- Orpius.Logging.Silverlight.dll
- Orpius.Logging.Silverlight.pdb
- Orpius.Logging.Silverlight.UI.dll
- Orpius.Logging.Silverlight.UI.pdb
- LineGraph
- Decav.Windows.Controls.LineGraph.dll
- Decav.Windows.Controls.LineGraph.pdb
- Log4Net
- Open Legion Solution.bat
- Source
- GridComputing
- GridComputing.sln
- GridComputing.suo
- GridComputing
- GridManager
- GridManagerWpf
- SilverlightAgent
- Website
- Libraries
- Decav.Windows.Controls.LineGraph
- LineGraph
- Tasks
- MutexExample
- Client
- Server
- PrimeFinder
- Client
- Server
- legionvs2008beta2.zip
|
/*
<File>
<Copyright>Copyright © 2007, Daniel Vaughan. All rights reserved.</Copyright>
<License see="prj:///Documentation/License.txt"/>
<Owner Name="Daniel Vaughan" Email="dbvaughan@gmail.com"/>
<CreationDate>2007-12-14 00:42:47Z</CreationDate>
<LastSubmissionDate>$Date: $</LastSubmissionDate>
<Version>$Revision: $</Version>
</File>
*/
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
namespace Orpius.GridComputing.Controls
{
/// <summary>
/// A glass button.
/// </summary>
public class ButtonControl : Control
{
readonly FrameworkElement root;
readonly Canvas rootCanvas;
readonly Rectangle rectangleColor;
readonly Rectangle rectangleShine;
readonly Rectangle hitShape;
readonly Storyboard mouseOverStoryboard;
readonly Storyboard mouseOutStoryboard;
readonly TextBlock textBlock;
/// <summary>
/// The padding for the text within the control.
/// </summary>
const int padding = 5;
/// <summary>
/// Set when the control is loaded, and used
/// to determine whether the control should be layed
/// out when the text changes.
/// </summary>
bool loaded;
/// <summary>
/// Gets or sets the text on the button.
/// </summary>
/// <value>The text on the button's face.</value>
public string Text
{
get
{
return textBlock.Text;
}
set
{
textBlock.Text = value;
LayoutControl();
}
}
#region Click event
event EventHandler<MouseEventArgs> click;
/// <summary>
/// Occurs when the button is clicked.
/// </summary>
public event EventHandler<MouseEventArgs> Click
{
add
{
click += value;
}
remove
{
click -= value;
}
}
protected void OnClick(MouseEventArgs e)
{
if (click != null)
{
click(this, e);
}
}
#endregion
public ButtonControl()
{
System.IO.Stream s = this.GetType().Assembly.GetManifestResourceStream("Orpius.GridComputing.Controls.ButtonControl.xaml");
root = InitializeFromXaml(new System.IO.StreamReader(s).ReadToEnd());
rootCanvas = (Canvas)root.FindName("GlassButton");
rectangleColor = (Rectangle)root.FindName("rectangleColor");
rectangleShine = (Rectangle)root.FindName("rectangleShine");
hitShape = (Rectangle)rootCanvas.FindName("HitShape");
textBlock = (TextBlock)rootCanvas.FindName("Text");
textBlock.Text = string.Empty;
mouseOverStoryboard = (Storyboard)rootCanvas.FindName("MouseOver");
mouseOutStoryboard = (Storyboard)rootCanvas.FindName("MouseOut");
hitShape.MouseEnter += new MouseEventHandler(hitShape_MouseEnter);
hitShape.MouseLeave += new EventHandler(hitShape_MouseLeave);
hitShape.MouseLeftButtonUp += new MouseEventHandler(hitShape_MouseLeftButtonUp);
Loaded += new EventHandler(ButtonControl_Loaded);
}
void ButtonControl_Loaded(object sender, EventArgs e)
{
loaded = true;
LayoutControl();
}
void hitShape_MouseLeftButtonUp(object sender, MouseEventArgs e)
{
OnClick(e);
}
void hitShape_MouseLeave(object sender, EventArgs e)
{
mouseOutStoryboard.Begin();
}
void hitShape_MouseEnter(object sender, MouseEventArgs e)
{
mouseOverStoryboard.Begin();
}
void LayoutControl()
{
if (!loaded)
{
return;
}
rectangleColor.Width = hitShape.Width = Width;
rectangleColor.Height = hitShape.Height = Height;
rectangleShine.Height = Height / 2.5;
if (Width < 2 * padding)
{
return;
}
textBlock.Width = Width - 2 * padding;
double textWidth = textBlock.Width;
double textWidthActual = textBlock.ActualWidth;
double textLeft = (Width - textWidthActual) / 2;
textBlock.SetValue(Canvas.LeftProperty, textLeft);
rectangleShine.Width = Width - 2 * padding;
double shineLeft = padding;
rectangleShine.SetValue(Canvas.LeftProperty, shineLeft);
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
Daniel is a former senior engineer in Technology and Research at the Office of the CTO at Microsoft, working on next generation systems.
Previously Daniel was a nine-time Microsoft MVP and co-founder of
Outcoder, a Swiss software and consulting company.
Daniel is the author of Windows Phone 8 Unleashed and Windows Phone 7.5 Unleashed, both published by SAMS.
Daniel is the developer behind several acclaimed mobile apps including
Surfy Browser for Android and Windows Phone. Daniel is the creator of a number of popular open-source projects, most notably
Codon.
Would you like Daniel to bring value to your organisation?
Please contact
Blog |
Twitter
Xamarin Experts
Windows 10 Experts