![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
|
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.
br> br> |
| |||||||
![]() |
| | Thread Tools | Display Modes |
| | #1 (permalink) |
| 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 |
| | #2 (permalink) |
| 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 |
| |
| |
![]() |
| 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 |