tags:

views:

512

answers:

2

I have a usercontrol called "InputSensitiveTextBox" that inherits from Textbox. It has a property I define called "CurrentInputType", which is of type "MyControlsNamespace.SupportedInputTypes" (with values Keyboard, Mouse, Touchpad, VirtualKey). I need to have this property be set in Xaml just like I might set "HorizontalAlignment" or "ScrollbarVisibility" as such:

MyControlsNamepsace.InputSensitiveTextBox Background="Black" CurrentInputType="Keyboard"

Please advise :)

+1  A: 

Is your CurrentInputType a dependency property?

If not here is the code for it to replace your old property:

public SupportedInputTypes CurrentInputType
{
    get { return (SupportedInputTypes)GetValue(CurrentInputTypeProperty); }
    set { SetValue(CurrentInputTypeProperty, value); }
}

// Using a DependencyProperty as the backing store for CurrentInputType.  This enables animation, styling, binding, etc...
public static readonly DependencyProperty CurrentInputTypeProperty =
    DependencyProperty.Register("CurrentInputType", typeof(SupportedInputTypes), typeof(InputSensitiveTextBox), new PropertyMetadata(SupportedInputTypes.Keyboard));

In the PropertyMetadata you define your default..

Hope this fixes your problem!

Arcturus
well the issue is that the markup doesn't know what a SupportedInputTypes type is. Not sure that a dependancy property will fix that...
Kamiikoneko
You can always set the value in xaml with the Static extension of course.. {x:Static local:SupportedInputTypes.Keyboard} .. Not the solution you want, but it works..
Arcturus
+1  A: 

You need to use the Static markup extenstion to reference your enumeration in xaml, You also need to add it's namespace to your namespace declarations.

xmlns:MyControlsNamepsace ="clr-namespace:MyControlsNamepsace"

<MyControlsNamepsace:InputSensitiveTextBox 
    CurrentInputType="{x:Static MyControlsNamepsace:SupportedInputTypes.Keyboard}"
    />
Ian Oakes