CSLA .NET

Vibrant discussion about CSLA .NET and using the framework to build great business applications.

Forum has moved

New location: CSLA .NET forum


CSLA .NET Resources:
  • CSLA .NET forum
  • CSLA .NET home page
  • TriggerAction customization

    rated by 0 users
    Answered (Verified) This post has 1 verified answer | 2 Replies | 1 Follower

    Top 500 Contributor
    22 Posts
    TygreWolf posted on Thu, Jun 27 2013 10:39 AM

    Two questions relating to the TriggerAction control and the XAML around it.  First, I've read Rocky's blog post here about the control.  My questions are:

    1. Does the TriggerEvent attribute absolutely have to be in the format

    public void MyAction(object sender, ExecuteEventArgs e)

    or can it be:

    public void MyAction(object sender, MyOwnEventArgs e) where MyOwnEventArgs inherits directly from System.EventArgs?

    2. After the TriggerEvent is defined, how can I use MethodParameter to define a particular parameter from the EventArgs to pass into a specific function (MethodName) that doesn't have the same signature?

    Example: MyOwnEventArgs contains a UserInfo object.  The Method which the TriggerAction will call only takes a UserInfo object.  What do I put as a MethodParameter value to pull the UserInfo object out of my event args and pass it to the LoadUser method?

    <
    v:UserList x:Name="UserList"/>
    <csla:TriggerAction x:Name="UserSelectedTrigger" 
    TargetControl
    ="{Binding ElementName=UserList}" 
    TriggerEvent
    ="OnUserSelected" 
    MethodName
    ="LoadUser" 
    MethodParameter
    ="???"/>


    -Jason

    Answered (Verified) Verified Answer

    Top 500 Contributor
    22 Posts
    Verified by TygreWolf

    Nevermind, found my answer.

    The correct usage is:

    <csla:TriggerAction x:Name="SelectedUserTrigger" TargetControl="{Binding ElementName=DgUsers}" TriggerEvent="SelectionChanged" MethodName="LoadUser" />

    All Replies

    Top 500 Contributor
    22 Posts

    Alright, I've simplified the design of my view a little bit.  I'm attempting to call a method "LoadUser" on my ViewModel when an item is selected on a datagrid.  I'm using a CSLA TriggerAction to do via the following code:

    <DataGrid x:Name="DgUsers" ItemsSource="{Binding Source={StaticResource UserListModelViewSource}}"
                  AlternatingRowBackground="AliceBlue" SelectionMode="Single" CanUserResizeRows="False" DockPanel.Dock="Top"
                  HorizontalAlignment="Stretch" ColumnWidth="*" CanUserAddRows="False" AutoGeneratingColumn="DgUsers_AutoGeneratingColumn">
    </DataGrid>
    <csla:TriggerAction x:Name="SelectedUserTrigger" TargetControl="{Binding ElementName=DgUsers, Path=SelectedItem}" MethodName="LoadUser" DockPanel.Dock="Bottom"/>

    At this point, I get first chance exceptions (2 similar, but not exact errors) occurring when I select a user in the grid:

    System.Windows.Data Error: 23 : Cannot convert 'Jane Smith' from type 'UserInfo' to type 'System.Windows.FrameworkElement' for 'en-US' culture with default conversions; consider using Converter property of Binding. NotSupportedException:'System.NotSupportedException: TypeConverter cannot convert from STIPEMSimulator.Library.BusinessObjects.Users.UserInfo.
       at System.ComponentModel.TypeConverter.GetConvertFromException(Object value)
       at System.ComponentModel.TypeConverter.ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, Object value)
       at MS.Internal.Data.DefaultValueConverter.ConvertHelper(Object o, Type destinationType, DependencyObject targetElement, CultureInfo culture, Boolean isForward)'
    A first chance exception of type 'System.NotSupportedException' occurred in PresentationFramework.dll
    System.Windows.Data Error: 6 : 'ObjectSourceConverter' converter failed to convert value 'Jane Smith' (type 'UserInfo'); fallback value will be used, if available. BindingExpression:Path=SelectedItem; DataItem='DataGrid' (Name='DgUsers'); target element is 'TriggerAction' (Name='SelectedUserTrigger'); target property is 'TargetControl' (type 'FrameworkElement') NotSupportedException:'System.NotSupportedException: TypeConverter cannot convert from STIPEMSimulator.Library.BusinessObjects.Users.UserInfo.
       at MS.Internal.Data.DefaultValueConverter.ConvertHelper(Object o, Type destinationType, DependencyObject targetElement, CultureInfo culture, Boolean isForward)
       at MS.Internal.Data.ObjectSourceConverter.Convert(Object o, Type type, Object parameter, CultureInfo culture)
       at System.Windows.Data.BindingExpression.ConvertHelper(IValueConverter converter, Object value, Type targetType, Object parameter, CultureInfo culture)'

    Any thoughts here?  The dgUsers data grid is bound to a CSLA ViewModel<UserList>, where UserList is a ReadOnlyList of UserInfo objects.

    Top 500 Contributor
    22 Posts
    Verified by TygreWolf

    Nevermind, found my answer.

    The correct usage is:

    <csla:TriggerAction x:Name="SelectedUserTrigger" TargetControl="{Binding ElementName=DgUsers}" TriggerEvent="SelectionChanged" MethodName="LoadUser" />

    Page 1 of 1 (3 items) | RSS

    Copyright (c) 2006-2014 Marimer LLC. All rights reserved.
    Email admin@lhotka.net for support.
    Powered by Community Server (Non-Commercial Edition), by Telligent Systems