|
|||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||
|
Announcements
Chapters
Services
Feature Zones
|
IntroductionAfter part 1, I decided to really concentrate on how to make the Item GenerationIn the previous version of the The private void PopulateLedger()
{
if (_ledgerItems != null)
{
for (int i = 0; i < 24; i++)
{
CalendarLedgerItem item = new CalendarLedgerItem();
item.TimeslotA = i.ToString();
item.TimeslotB = "00";
item.SetBinding(CalendarLedgerItem.StyleProperty,
GetOwnerBinding("CalendarLedgerItemStyle"));
_ledgerItems.Children.Add(item);
}
}
}
The Style, Style, Style
The All the styles are exposed as public static readonly DependencyProperty CalendarTimeslotItemStyleProperty =
DependencyProperty.Register("CalendarTimeslotItemStyle",
typeof(Style), typeof(Calendar));
public Style CalendarTimeslotItemStyle
{
get { return (Style)GetValue(CalendarTimeslotItemStyleProperty); }
set { SetValue(CalendarTimeslotItemStyleProperty, value); }
}
All that is now left to do is bind the timeslot.SetBinding(CalendarTimeslotItem.StyleProperty,
GetOwnerBinding("CalendarTimeslotItemStyle"));
NamespacesBy adding the following attribute... [assembly: XmlnsDefinition(http://schemas.rudigrobler.com/wpf/2008,
"RudiGrobler.Controls")]
... it is now very easy to reference my controls without needing to remember all the namespaces: xmlns:rg=”http://schemas.rudigrobler.com/wpf/2008”
Design Time SupportVisual Studio and Expression Blend design time support is currently a hot topic! <>
The To remove controls from the toolbox, add the following attribute: [ToolboxBrowsable(false)]
Also notice the “cool” custom icon I now have! This is achieved by adding an embedded resource with a specific name (Calendar.Icon.bmp). The icon can also be specified by using the
In Expression Blend, the property grid gets divided into categories! [Category("Calendar")]
Each category also gets subdivided into a “Normal” section and an expander that has some “Advanced” properties. To place a property in the “Advanced” expander: [EditorBrowsable(EditorBrowsableState.Advanced)]
Or to place it in the “Normal” section: [EditorBrowsable(EditorBrowsableState.Always)]
Named PartsA common practice in designing reusable controls is to use named parts! In my <calendarledger x:name="PART_Ledger" />
The next step is to override the CalendarDay _day;
public override void OnApplyTemplate()
{
base.OnApplyTemplate();
_day = GetTemplateChild(ElementDay) as CalendarDay;
if (_day != null)
{
_day.Owner = this;
}
}
In Now, I have full access to the public Calendar Owner { get; set; }
private BindingBase GetOwnerBinding(string propertyName)
{
Binding result = new Binding(propertyName);
result.Source = this.Owner;
return result;
}
A best practice in using named parts is to always start the name with [TemplatePart(Name = CalendarLedger.ElementLedgerItems, Type = typeof(StackPanel))]
This attribute makes it easy to determine what type a named part should be! SummaryThat is it for part 2!!! History
|
||||||||||||||||||||||||||||||||||||||||