Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > Avalon

Vista - How to bind a Trigger to a user defined DependencyProperty

 
 
Old 03-14-2006   #1 (permalink)
Philippe Lavoie


 
 

How to bind a Trigger to a user defined DependencyProperty

Hi

I do the following inside my code

public partial class ShoppingCart : StackPanel, INotifyPropertyChanged
{
public ShoppingCart()
{
InitializeComponent();
}


public static readonly DependencyProperty StatusProperty =
DependencyProperty.Register("Status", typeof(string),
typeof(ShoppingCart), new PropertyMetadata("unset"));

// You must provide CLR accessors for your property
public string Status
{
get { return (string)GetValue(StatusProperty); }
set
{
SetValue(StatusProperty, value);
HandlePropertyChanged("Status");
}
}


Inside the XAML I have something like

<StackPanel x:Class="AlpineWebApplication.ShoppingCart"
xmlns="http://schemas.microsoft.com/winfx/avalon/2005"
xmlns:x="http://schemas.microsoft.com/winfx/xaml/2005"
Orientation="Horizontal"
xmlns:System="System"
xmlns:Microsoft_Windows_Themes="Microsoft_Windows_Themes"
Width="15" ClipToBounds="True"
xmlns:d="http://schemas.microsoft.com/expression/interactivedesigner/2005"
xmlns:c="http://schemas.microsoft.com/winfx/2005/06/markup-compatibility"
c:Ignorable="d"
x:Name="ShoppingCartControl"
>

<StackPanel.Triggers>
<Trigger Property="ShoppingCart.Status" Value="Expand"
SourceName="ShoppingCartControl">
<Trigger.EnterActions>
<BeginStoryboard Storyboard="{StaticResource ExpandCart}"
x:Name="ExpandCart_BeginStoryboard"/>
</Trigger.EnterActions>
</Trigger>
....


However, when I execute all the above, I get this nice error message
which, unfortunately, means nothing to me:

Error at element 'Trigger' in markup file 'shoppingcart.xaml' : The
string 'ShoppingCart.Status' could not be set on the 'Property' property
which is of type 'DependencyProperty'. Please see the sdk documentation
for the Property property and the DependencyProperty class for an
explanation of allowable values..

I also tried to only use 'Status', "{Binding Path=Status}" for the
Property value and it didn't help.

Please enlighten me.

Thanks

Phil


My System SpecsSystem Spec
Old 03-15-2006   #2 (permalink)
Marcus


 
 

Re: How to bind a Trigger to a user defined DependencyProperty

You have to define a xmlns namespace for your "AlpineWebApplication"
project.

Add the following declaration to your root element attributes:

xmlns:local="clr-namespace=AlpineWebApplication"

and then, when declaring your trigger, you could do the following:

<Trigger Property="local:ShoppingCart.Status" Value="Expand">

While I did not try this particular solution myself, I encountered
similar problems and resolved it using the xmlns for my current
project...

the "SourceName" element is usefull when you want to declare a Trigger
on another element property... (e.g. if you have a child element and
want to trigger on one of its property)...

Try this and let me know if it solved your issue..

Bonne chance!!!

Marcus

Philippe Lavoie wrote:
> Hi
>
> I do the following inside my code
>
> public partial class ShoppingCart : StackPanel, INotifyPropertyChanged
> {
> public ShoppingCart()
> {
> InitializeComponent();
> }
>
>
> public static readonly DependencyProperty StatusProperty =
> DependencyProperty.Register("Status", typeof(string),
> typeof(ShoppingCart), new PropertyMetadata("unset"));
>
> // You must provide CLR accessors for your property
> public string Status
> {
> get { return (string)GetValue(StatusProperty); }
> set
> {
> SetValue(StatusProperty, value);
> HandlePropertyChanged("Status");
> }
> }
>
>
> Inside the XAML I have something like
>
> <StackPanel x:Class="AlpineWebApplication.ShoppingCart"
> xmlns="http://schemas.microsoft.com/winfx/avalon/2005"
> xmlns:x="http://schemas.microsoft.com/winfx/xaml/2005"
> Orientation="Horizontal"
> xmlns:System="System"
> xmlns:Microsoft_Windows_Themes="Microsoft_Windows_Themes"
> Width="15" ClipToBounds="True"
> xmlns:d="http://schemas.microsoft.com/expression/interactivedesigner/2005"
> xmlns:c="http://schemas.microsoft.com/winfx/2005/06/markup-compatibility"
> c:Ignorable="d"
> x:Name="ShoppingCartControl"
> >

> <StackPanel.Triggers>
> <Trigger Property="ShoppingCart.Status" Value="Expand"
> SourceName="ShoppingCartControl">
> <Trigger.EnterActions>
> <BeginStoryboard Storyboard="{StaticResource ExpandCart}"
> x:Name="ExpandCart_BeginStoryboard"/>
> </Trigger.EnterActions>
> </Trigger>
> ...
>
>
> However, when I execute all the above, I get this nice error message
> which, unfortunately, means nothing to me:
>
> Error at element 'Trigger' in markup file 'shoppingcart.xaml' : The
> string 'ShoppingCart.Status' could not be set on the 'Property' property
> which is of type 'DependencyProperty'. Please see the sdk documentation
> for the Property property and the DependencyProperty class for an
> explanation of allowable values..
>
> I also tried to only use 'Status', "{Binding Path=Status}" for the
> Property value and it didn't help.
>
> Please enlighten me.
>
> Thanks
>
> Phil


My System SpecsSystem Spec
 

Thread Tools


Similar Threads
Thread Forum
Re: User defined functions. VB Script
Check if user defined in SD VB Script
How do I set User Right on Bypass traverse checking to 'Not Defined'? Vista security
User-defined sorting Vista file management


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46