Skip to content

Instantly share code, notes, and snippets.

@JakeGinnivan
Created August 25, 2012 04:17
Show Gist options
  • Select an option

  • Save JakeGinnivan/3460633 to your computer and use it in GitHub Desktop.

Select an option

Save JakeGinnivan/3460633 to your computer and use it in GitHub Desktop.
//In generic.xaml
<Style TargetType="{x:Type Scaffolding:SearchScaffold}">
<Setter Property="BorderThickness"
Value="0" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Scaffolding:SearchScaffold}">
<Controls:MetroContentControl>
<Border Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
SnapsToDevicePixels="True">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<ContentControl Content="{TemplateBinding HeaderContent}"
Grid.Column="0"
Grid.ColumnSpan="2"
KeyboardNavigation.IsTabStop="False"
Grid.Row="0"
Margin="0 0 0 5" />
<Border Grid.Row="1"
BorderBrush="DarkGray"
BorderThickness="0 0 1 0">
<ContentControl Content="{TemplateBinding SearchContent}"
Width="230"
KeyboardNavigation.IsTabStop="False"
HorizontalAlignment="Stretch" />
</Border>
<ContentControl Content="{TemplateBinding MainContent}"
Grid.Column="1"
KeyboardNavigation.IsTabStop="False"
Grid.Row="1"
Margin="5 0 0 0" />
<ContentControl Content="{TemplateBinding FooterContent}"
Grid.Column="1"
Grid.Row="2"
KeyboardNavigation.IsTabStop="False"
Margin="0 5 0 0" />
</Grid>
</Border>
</Controls:MetroContentControl>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
using System.Windows;
using System.Windows.Controls;
using System.Windows.Markup;
namespace CCWin.App.Infrastructure.Scaffolding
{
/// <summary>
/// Follow steps 1a or 1b and then 2 to use this custom control in a XAML file.
///
/// Step 1a) Using this custom control in a XAML file that exists in the current project.
/// Add this XmlNamespace attribute to the root element of the markup file where it is
/// to be used:
///
/// xmlns:MyNamespace="clr-namespace:CCWin.App.Infrastructure.Scaffolding"
///
///
/// Step 1b) Using this custom control in a XAML file that exists in a different project.
/// Add this XmlNamespace attribute to the root element of the markup file where it is
/// to be used:
///
/// xmlns:MyNamespace="clr-namespace:CCWin.App.Infrastructure.Scaffolding.Scaffolding"
///
/// You will also need to add a project reference from the project where the XAML file lives
/// to this project and Rebuild to avoid compilation errors:
///
/// Right click on the target project in the Solution Explorer and
/// "Add Reference"->"Projects"->[Browse to and select this project]
///
///
/// Step 2)
/// Go ahead and use your control in the XAML file.
///
/// <MyNamespace:SummaryContentActions/>
///
/// </summary>
[ContentProperty("MainContent")]
public class SearchScaffold : ContentControl
{
static SearchScaffold()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(SearchScaffold), new FrameworkPropertyMetadata(typeof(SearchScaffold)));
}
public object SearchContent
{
get { return (object)GetValue(SearchContentProperty); }
set { SetValue(SearchContentProperty, value); }
}
// Using a DependencyProperty as the backing store for SearchContent. This enables animation, styling, binding, etc...
public static readonly DependencyProperty SearchContentProperty =
DependencyProperty.Register("SearchContent", typeof(object), typeof(SearchScaffold), new UIPropertyMetadata(null));
public object MainContent
{
get { return (object)GetValue(MainContentProperty); }
set { SetValue(MainContentProperty, value); }
}
// Using a DependencyProperty as the backing store for MainContent. This enables animation, styling, binding, etc...
public static readonly DependencyProperty MainContentProperty =
DependencyProperty.Register("MainContent", typeof(object), typeof(SearchScaffold), new UIPropertyMetadata(null));
public object FooterContent
{
get { return (object)GetValue(FooterContentProperty); }
set { SetValue(FooterContentProperty, value); }
}
// Using a DependencyProperty as the backing store for ActionsContent. This enables animation, styling, binding, etc...
public static readonly DependencyProperty FooterContentProperty =
DependencyProperty.Register("FooterContent", typeof(object), typeof(SearchScaffold), new UIPropertyMetadata(null));
public object HeaderContent
{
get { return (object)GetValue(HeaderContentProperty); }
set { SetValue(HeaderContentProperty, value); }
}
// Using a DependencyProperty as the backing store for ActionsContent. This enables animation, styling, binding, etc...
public static readonly DependencyProperty HeaderContentProperty =
DependencyProperty.Register("HeaderContent", typeof(object), typeof(SearchScaffold), new UIPropertyMetadata(null));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment