DependencyProperty Orientation problem
Posted
by byte
on Stack Overflow
See other posts from Stack Overflow
or by byte
Published on 2010-05-04T16:10:30Z
Indexed on
2010/05/04
16:18 UTC
Read the original article
Hit count: 213
I am learning WPF and am trying to create my first UserControl. My UserControl consists of
- StackPanel
- StackPanel contains a Label and TextBox
I am trying to create two Dependency Properties
- Text for the Label
- Orientation for the StackPanel - The orientation will affect the position of the Label and TextBox effectively
I have successfully created a Text dependency property and bind it to my UserControls . But when I created the Orientation property, I seem to get following error in get property
The as operator must be used with a reference type or nullable type ('System.Windows.Controls.Orientation' is a non-nullable value type)
public static DependencyProperty OrientationProperty = DependencyProperty.Register("Orientation", typeof(System.Windows.Controls.Orientation), typeof(MyControl), new PropertyMetadata((System.Windows.Controls.Orientation)(Orientation.Horizontal)));
public Orientation Orientation
{
get { return GetValue(OrientationProperty) as System.Windows.Controls.Orientation; }
set { SetValue(OrientationProperty, value); }
}
Appreciate your help.
© Stack Overflow or respective owner