Windows Vista Forums
Vista Forums Home Join Vista Forums Donate Vista Tutorials Tags

Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
Register at Vista forums...the world biggest Windows Vista resource Join Vista Forums Now

Go Back   Vista Forums > Microsoft Technical Newsgroups > Avalon

How to bind a Trigger to a user defined DependencyProperty

Closed Thread
 
Thread Tools Display Modes
Old 03-14-2006   #1 (permalink)
Philippe Lavoie
Guest


 

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

Old 03-15-2006   #2 (permalink)
Marcus
Guest


 

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


Closed Thread

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I set User Right on Bypass traverse checking to 'Not Defined'? trey.jonn Vista security 2 4 Weeks Ago 09:26 AM
Winforms User Controls - How do I bind those to a dataset on the host form John Sheppard .NET General 0 04-14-2008 09:49 PM
User-defined sorting Dennis Snelgrove Vista file management 1 05-14-2007 02:05 AM
C++/CLI based DependencyProperty example =?Utf-8?B?Sm9obiBEdW5u?= Avalon 0 08-23-2006 04:57 PM
Trigger on user dependency property Griff Avalon 1 01-31-2006 06:59 AM








Vistax64.com 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 2005-2008

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 47 48 49 50