Replace Expander's Content at Runtime
-
I'm trying to create a specialized expander that has some pre-defined controls in place of the ContentPresenter. I created a class called CustomExpander. The content I want to place can be layed out differently depending on a DP called ContentAlignment. When set to Left, the content is arranged one way, and when set to right, the content is arranged another way. I'm trying to do this with different ContentControl.
public class CustomExpander : Expander
{
#region DP's
#region DP ContentAlignment
public static readonly DependencyProperty ContentAlignmentProperty =
DependencyProperty.Register("ContentAlignment",
typeof(ContentAlignment),
typeof(CustomExpander),
new PropertyMetadata(ContentAlignment.Left, new PropertyChangedCallback(OnContentAlignmentChanged)));public ContentAlignment ContentAlignment { get { return (ContentAlignment)GetValue(ContentAlignmentProperty); } set { SetValue(ContentAlignmentProperty, value); } } private static void OnContentAlignmentChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { var control = (CustomExpander)d; } #endregion #endregion #region CTOR static CustomExpander() { DefaultStyleKeyProperty.OverrideMetadata(typeof(CustomExpander), new FrameworkPropertyMetadata(typeof(CustomExpander))); } #endregion
}
public enum ContentAlignment
{
Left,
Right
}Here's my style so far: