Invalid PropertyDescriptor Value -- please help!

I'm using the Feb CTP, and I'm trying to use a property in a trigger. Here's the specific XAML:

<Window x:Class="TestThingie.Window2"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Renamer" Height="300" Width="300"
>

<Window.Triggers>
<Trigger Property="Test" Value="True">
<Setter Property="Window2.Background" Value="Blue" />
</Trigger>
</Window.Triggers>
</Window>

In the codebehind I have a dependency property called 'Test'. When in the IDE I switch from XAML view to Design view, I get the error: "Invalid PropertyDescriptor Value", on the 'Property="Test"' section of the Trigger.

What am I missing :(



Answer this question

Invalid PropertyDescriptor Value -- please help!

  • BruceTT

    By the way, I have run the sample posted by Simon but with bool instead of int and it is working fine. Don't forget to rebuild the entire solution before running it, there is a bug in Feb CTP.


  • Aggag

    Thanks for the help Simon. :)
  • Lorenz Buchberger

    As chaz pointed out in the other thread...

    public static readonly DependencyProperty TestProperty = DependencyProperty.RegisterAttached("Test", typeof(int), typeof(Window2), new UIPropertyMetadata(false));



  • satishdayala

    I've done this with an int rather than a bool but...

    If you set your property up as an attached dependency property and then call SetValue to change it, the style of your contol will change. You need to decalre an xmlns specifier for the assembly that your class is in, and then reference the property by 'xmlns:class.property'.

    <Window x:Class="TestThingie.Window2"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Renamer" Height="300" Width="300"
    xmlns:local="clr-namespace:TestThingie;assembly=TestThingie">

    <Window.Resources>
    <
    Style TargetType="{x:Type Button}">
    <
    Style.Triggers>
    <
    Trigger Property="local:Window2.Test" Value="0">
    <
    Setter Property="BitmapEffect">
    <
    Setter.Value>
    <
    OuterGlowBitmapEffect GlowColor="Red" GlowSize="4"/>
    </
    Setter.Value>
    </
    Setter>
    </
    Trigger>
    </
    Style.Triggers>
    </
    Style>
    </
    Window.Resources>

    <
    Grid Margin="20">
    <
    Button x:Name="MyButton" Content="Click me" Height="25" Click="OnClick"/>
    </
    Grid>
    </
    Window>


    public
    partial class Window2 : Window
    {
    [BindableAttribute(true
    )]
    public int
    Test
    {
    get { return (int
    )GetValue(TestProperty); }
    set { SetValue(TestProperty, value
    ); }
    }

    public static readonly DependencyProperty TestProperty = DependencyProperty.RegisterAttached("Test", typeof(int), typeof(Window2), new UIPropertyMetadata
    (0));

    public static int GetTest(UIElement
    element)
    {
    return (int
    )element.GetValue(TestProperty);
    }

    public static void SetTest(UIElement element, int
    value)
    {
    if (element != null
    )
    {
    element.SetValue(TestProperty, value);
    }
    else
    {
    throw new ArgumentNullException
    ();
    }
    }

    public
    Window2()
    {

    }

    void OnClick(object sender, RoutedEventArgs
    e)
    {
    SetTest(this
    .MyButton, 5);
    }
    }



  • Rochak

    There really isn't much to post - just the DependancyProperty (used the Insert Snippet functionality) and I set the value of the property in the window object's constructor.

     

    public partial class Window2 : Window {
        public bool Test {
            get { return (bool)GetValue(TestProperty); }
            set { SetValue(TestProperty, value); }
        }

        // Using a DependencyProperty as the backing store for Test.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty TestProperty =
            DependencyProperty.Register("Test", typeof(bool), typeof(Window2), new UIPropertyMetadata(0));

        public Window2() {
            InitializeComponent();
           
            Test = true;
        }
    }


  • ron2464

    It looks like a schema issue, ignore it. However, you'll need to wrap your trigger up in a style and give the style a target type. Here's an example with a button an IsMouseOver

    You might have issues with creating a dp in the code behind for your window, try doing it in a custom control.

    <Window x:Class="TriggersTest.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="TriggersTest" Height="300" Width="300">
    <
    Window.Resources>
    <
    Style TargetType="{x:Type Button}">
    <
    Style.Triggers>
    <
    Trigger Property="IsMouseOver" Value="True">
    <
    Setter Property="Background" Value="Blue"/>
    </
    Trigger>
    </
    Style.Triggers>
    </
    Style>
    </
    Window.Resources>

    <Grid Margin="20">
    <
    Button Content="Hover Over Me" Height="25"/>
    </
    Grid>
    </
    Window>



  • CliftNorris

    That's why I did it as an int... :)

    If you breakpoint on the DependencyProperty initializer and do a quick watch on that line you'll notice it throws an ArugmentException saying that the specified type doesn't match that of the property.

    Stick with the int for now, I've posted another question about the bool...



  • Ryo

    Can you post the relavent bit from the codebehind

  • Laurensvp

    Okay, that works.

    Course when I try to change the property from int to bool, it blows up..........

    *sigh* What am I doing wrong

    By 'blows up' I mean that when I run the application, I get an exception at "App.Run()" in app.xaml.cs, with this text:

    System.Windows.Markup.BamlParseException was unhandled
    Message="Error at element '' in markup file 'Window2.xaml' : Exception has been thrown by the target of an invocation.."
    Source="PresentationFramework"

    Doesn't mean squat to me... There's a huge stack trace after this but nothing pointing at my code.


  • Seb69

    Okay, that works, but it isn't what I want.

    What I want is to be able to use a property of the Window1 class to modify the style of a single specific control via triggers.


  • a_takavci

    I have been rebuilding the entire solution - in fact, I created a whole new one, pasted in the code, and ran it with the same result - exception.


  • Invalid PropertyDescriptor Value -- please help!