none
Defining a Dependency Property on UserControl?

    Question

  • I'm trying to create a custom DependencyProperty for a user control I'm building that inherits from the CheckBox class.  The property I'm creating is "IsReadOnly".  I've created a bunch of other dependency properties before and accessed them from my resource dictionary via templates, but for some reason I'm getting an error on this one - it says it can't find the property IsReadOnly.

     

    My C# code:

     

    Code Snippet

    ///

    /// Property to set the IsReadOnly attribute

    ///

    public bool IsReadOnly

    {

    get { return (bool)GetValue(IsReadOnlyProperty); }

    set { SetValue(IsReadOnlyProperty, value); }

    }

    public static readonly DependencyProperty IsReadOnlyProperty

    = DependencyProperty.Register("IsReadOnly",

    typeof(bool),

    typeof(EclpCheckBox),

    new FrameworkPropertyMetadata(false));

     

     

    How I'm trying to access it from a trigger:

     

    Code Snippet

    <Trigger Property="IsReadOnly" Value="true">

    <Setter Property="Focusable" Value="False" />

    </Trigger>

     

     

    Can anyone see what I'm doing wrong? 
    Friday, March 7, 2008 8:29 PM

Answers

  • Hi Kofoed,

     

    did you also try

     

    Code Snippet

    <Trigger Property="EclpCheckBox.IsReadOnly" Value="true">

    <Setter Property="Focusable" Value="False" />

    </Trigger>

     

     

    Friday, March 7, 2008 10:17 PM

All replies

  • What is really strange is that I can't seem to define any dependency properties for controls that inherit from either CheckBox or RadioButton that can be used from xaml triggers ... so bizarre.

     

    Is there anything in these controls that would prevent me from doing this?

    Friday, March 7, 2008 10:04 PM
  • Hi Kofoed,

     

    did you also try

     

    Code Snippet

    <Trigger Property="EclpCheckBox.IsReadOnly" Value="true">

    <Setter Property="Focusable" Value="False" />

    </Trigger>

     

     

    Friday, March 7, 2008 10:17 PM
  • Good one!  Didn't think I'd have to do that since I didn't for other controls.

     

    I actually had to do this:

     

    Code Snippet

    <Trigger Property="local:EclpCheckBox.IsReadOnly" Value="true">

    <Setter Property="Focusable" Value="False" />

    </Trigger>

     

     

    Friday, March 7, 2008 10:28 PM