- Source_Code.zip
- Source Code
- Apex
- Apex.sln
- Silverlight
- Apex.Silverlight
- Adorners
- Apex.Silverlight.csproj
- Apex.Silverlight.csproj.user
- Commands
- Consistency
- Controls
- Converters
- Design
- DragAndDrop
- Extensions
- MVVM
- Properties
- Themes
- Samples
- CommandingSample
- ControlsSample
- DragAndDropSample
- MVVMSample
- WP7
- Apex.WP7
- Apex.WP7.csproj
- Commands
- Consistency
- Controls
- Converters
- Extensions
- MVVM
- Properties
- Samples
- CommandingSample
- ControlsSample
- MVVMSample
- WPF
- Apex
- Adorners
- Apex.csproj
- Commands
- Consistency
- Controls
- Converters
- Design
- DragAndDrop
- Extensions
- MVVM
- Properties
- Snippets
- .vscontent
- InsertAttachedProperty.snippet
- InsertDependencyProperty.snippet
- InsertNotifyingProperty.snippet
- InsertViewModelCommand.snippet
- Themes
- Samples
- CommandingExample
- ControlsSample
- DragAndDropSample
- MVVMSample
- Apex_Binaries.zip
- Apex Binaries
- Apex.dll
- Apex.Silverlight.dll
- Apex.WP7.dll
- Example_Applications.zip
- Example Applications
- Silverlight
- WP7
- WPF
- Apex.dll
- CommandingSample.exe
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.ComponentModel;
namespace Apex.Controls
{
/// <summary>
/// The PaddedGrid control is a Grid that supports padding.
/// </summary>
public class PaddedGrid : ApexGrid
{
/// <summary>
/// Initializes a new instance of the <see cref="PaddedGrid"/> class.
/// </summary>
public PaddedGrid()
{
// Add a loded event handler.
Loaded += new RoutedEventHandler(PaddedGrid_Loaded);
}
/// <summary>
/// Handles the Loaded event of the PaddedGrid control.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="System.Windows.RoutedEventArgs"/> instance containing the event data.</param>
void PaddedGrid_Loaded(object sender, RoutedEventArgs e)
{
// Get the number of children.
int childCount = VisualTreeHelper.GetChildrenCount(this);
// Go through the children.
for (int i = 0; i < childCount; i++)
{
// Get the child.
DependencyObject child = VisualTreeHelper.GetChild(this, i);
// Create the binding.
Binding binding = new Binding();
binding.Source = this;
binding.Path = new PropertyPath("Padding");
// Bind the child's margin to the grid's padding.
BindingOperations.SetBinding(child, FrameworkElement.MarginProperty, binding);
}
}
/// <summary>
/// Called when the padding changes.
/// </summary>
/// <param name="dependencyObject">The dependency object.</param>
/// <param name="args">The <see cref="System.Windows.DependencyPropertyChangedEventArgs"/> instance containing the event data.</param>
private static void OnPaddingChanged(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs args)
{
// Get the padded grid that has had its padding changed.
PaddedGrid me = dependencyObject as PaddedGrid;
if (me != null)
{
// Use an explicit 'InvalidateArrange', rather than the AffectsMeasure FrameworkPropertyMetadataOptions flag
// as these flags aren't available in Silverlight - this method will work in SL and WPF.
me.InvalidateArrange();
}
}
/// <summary>
/// The internal dependency property object for the 'Padding' property.
/// </summary>
private static readonly DependencyProperty PaddingProperty =
DependencyProperty.Register("Padding", typeof(Thickness), typeof(PaddedGrid),
new PropertyMetadata(new Thickness(0.0), new PropertyChangedCallback(OnPaddingChanged)));
/// <summary>
/// Gets or sets the padding.
/// </summary>
/// <value>The padding.</value>
[Description("The padding property."), Category("Common Properties")]
public Thickness Padding
{
get { return (Thickness)GetValue(PaddingProperty); }
set { SetValue(PaddingProperty, value); }
}
}
}
|
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.