![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| 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. |
| |||||||
| |
| | #1 (permalink) |
| | 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 Specs![]() |
| | #2 (permalink) |
| | 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 Specs![]() |
| 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 | |||