Note that there are some explanatory texts on larger screens.

plurals
  1. POCSLA Silverlight project (C#) Sample N-Tier Application (Adding Delete Functionality)
    primarykey
    data
    text
    <p>I know this is a very specific question, but I'm trying to get a grasp on the CSLA framework. I've successfully loaded up the "Sample N-Tier" application that can be found here:</p> <p><a href="http://lhotka.net/files/csla40/CslaSamples-4.3.13.zip" rel="nofollow">http://lhotka.net/files/csla40/CslaSamples-4.3.13.zip</a></p> <p>The Sample N-Tier silverlight application allows you to add LineItem objects to a collection LineItems, which, along with a Customer Name and Customer ID field make up the Order object.</p> <p>I'm trying to expand the functionality of the app as an exercise making the line items deletable. The code below is from the OrderVM.cs file and defines the functionality of the "Add" button click event. It invokes the Model.LineItems.AddNew() method, which doesn't take any parameters. I want to delete the <em>selected</em> LineItem, rather than just the first item, as I've got it coded write now. My code works, but I cannot figure out how to retrieve a LineItem object or an index/id of the line that I have currently selected.</p> <pre><code>namespace SilverlightUI { public class OrderVm : ViewModel&lt;BusinessLibrary.Order&gt; { public OrderVm() { //BeginRefresh(BusinessLibrary.Order.NewOrder); BeginRefresh(callback =&gt; BusinessLibrary.Order.GetOrder(231, callback)); } protected override void OnError(Exception error) { Bxf.Shell.Instance.ShowError(error.Message, "Error"); } public override void AddNew(object sender, ExecuteEventArgs e) { Model.LineItems.AddNew(); } public override void Remove(object sender, ExecuteEventArgs e) { //Bxf.Shell.Instance.ShowError(Model.LineItems.AllowRemove.ToString(), "Delete"); if(Model.LineItems.Count&gt;0) Model.LineItems.RemoveAt(0); } } } </code></pre> <p>Could someone explain how to go about retrieving a LineItem Object from the selected DataGrid Row?</p> <p>Thanks!</p> <p>EDIT: Posted below is the XAML for the OrderEdit.xaml file.</p> <pre><code> &lt;UserControl xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:csla="clr-namespace:Csla.Xaml;assembly=Csla.Xaml" xmlns:cslaRules="clr-namespace:Csla.Rules;assembly=Csla" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk" xmlns:my="clr-namespace:SilverlightUI" xmlns:System="clr-namespace:System;assembly=mscorlib" xmlns:c="clr-namespace:System.Windows.Controls;assembly=System.Windows" xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity" xmlns:ei="http://schemas.microsoft.com/expression/2010/interactions" x:Class="SilverlightUI.OrderEdit" mc:Ignorable="d" d:DesignHeight="410" d:DesignWidth="667" Loaded="UserControl_Loaded"&gt; &lt;UserControl.Resources&gt; &lt;ResourceDictionary&gt; &lt;ResourceDictionary.MergedDictionaries&gt; &lt;ResourceDictionary Source="./Themes/CslaSampleResources.xaml" /&gt; &lt;/ResourceDictionary.MergedDictionaries&gt; &lt;CollectionViewSource x:Key="orderVmViewSource" d:DesignSource="{d:DesignInstance my:OrderVm, CreateList=True}" /&gt; &lt;CollectionViewSource x:Key="orderVmLineItemsViewSource" Source="{Binding LineItems, Source={StaticResource orderVmViewSource}}" /&gt; &lt;/ResourceDictionary&gt; &lt;/UserControl.Resources&gt; &lt;Border Padding="0,10,0,0" CornerRadius="10,10,0,0"&gt; &lt;Border.Background&gt; &lt;LinearGradientBrush EndPoint="1.005,0.5" StartPoint="0,0.5"&gt; &lt;GradientStop Color="#7FFFFFFF" Offset="0"/&gt; &lt;GradientStop Color="#99FFFFFF" Offset="1"/&gt; &lt;/LinearGradientBrush&gt; &lt;/Border.Background&gt; &lt;Grid x:Name="LayoutRoot" DataContext="{Binding Source={StaticResource orderVmViewSource}}"&gt; &lt;Grid.ColumnDefinitions&gt; &lt;ColumnDefinition Width="Auto" /&gt; &lt;ColumnDefinition Width="*" /&gt; &lt;/Grid.ColumnDefinitions&gt; &lt;Grid.RowDefinitions&gt; &lt;RowDefinition Height="Auto" /&gt; &lt;RowDefinition Height="Auto" /&gt; &lt;RowDefinition Height="Auto" /&gt; &lt;RowDefinition Height="*" /&gt; &lt;RowDefinition Height="Auto" /&gt; &lt;/Grid.RowDefinitions&gt; &lt;TextBlock Text="Customer Id:" Grid.Column="0" Grid.Row="0" Style="{StaticResource LabelTextStyle}" /&gt; &lt;TextBox Grid.Column="1" Grid.Row="0" x:Name="idTextBox" Text="{Binding Model.Id, Mode=OneWay}" Style="{StaticResource TextBoxStyle}" /&gt; &lt;TextBlock Text="Customer Name:" Grid.Column="0" Grid.Row="1" Style="{StaticResource LabelTextStyle}" /&gt; &lt;TextBox Grid.Column="1" Grid.Row="1" x:Name="customerNameTextBox" Text="{Binding Model.CustomerName, Mode=TwoWay, ValidatesOnNotifyDataErrors=False}" Style="{StaticResource TextBoxStyle}" /&gt; &lt;!--&lt;csla:PropertyInfo Property="{Binding Path=Model.CustomerName}" x:Name="pi" /&gt;--&gt; &lt;TextBlock Grid.Row="2" Grid.ColumnSpan="2" Text="orders" Style="{StaticResource SubHeadingTextStyle}" Margin="10,15,0,0" /&gt; &lt;sdk:DataGrid Grid.Row="3" Grid.ColumnSpan="2" AutoGenerateColumns="False" ItemsSource="{Binding Model.LineItems}" x:Name="lineItemsDataGrid" RowDetailsVisibilityMode="VisibleWhenSelected" RowBackground="{x:Null}" BorderBrush="{x:Null}" HorizontalGridLinesBrush="{x:Null}" VerticalGridLinesBrush="{x:Null}" GridLinesVisibility="None" Background="White" ColumnHeaderHeight="35" ColumnHeaderStyle="{StaticResource DataGridHeaderStyle}" RowStyle="{StaticResource DataGridRowStyle}" CellStyle="{StaticResource DataGridCellStyle}"&gt; &lt;sdk:DataGrid.Columns&gt; &lt;sdk:DataGridTextColumn x:Name="idColumn" Binding="{Binding Id}" Header="ID" Width="Auto" /&gt; &lt;sdk:DataGridTextColumn x:Name="nameColumn" Binding="{Binding Name}" Header="NAME" Width="*" /&gt; &lt;/sdk:DataGrid.Columns&gt; &lt;/sdk:DataGrid&gt; &lt;Button Grid.Row="3" Grid.Column="1" x:Name="AddNewButton" HorizontalAlignment="Right" VerticalAlignment="Top" Margin="0,5,10,5" Style="{StaticResource AddButtonStyle}" /&gt; &lt;csla:TriggerAction TargetControl="{Binding ElementName=AddNewButton}" MethodName="AddNew" DataContext="{Binding CurrentItem}" /&gt; &lt;Button Grid.Row="3" Grid.Column="1" x:Name="DeleteButton" HorizontalAlignment="Right" VerticalAlignment="Top" Margin="0,5,10,5" /&gt; &lt;csla:TriggerAction TargetControl="{Binding ElementName=DeleteButton}" MethodName="Remove" DataContext="{Binding CurrentItem}" /&gt; &lt;Border Grid.Row="4" Grid.ColumnSpan="2" Background="#FFE0E0E0" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" /&gt; &lt;StackPanel Grid.Row="4" x:Name="stackPanel1" DataContext="{Binding CurrentItem}" Orientation="Horizontal" VerticalAlignment="Center" HorizontalAlignment="Right" Grid.Column="1"&gt; &lt;Button Content="cancel" x:Name="CancelButton" IsEnabled="{Binding CanCancel}" Margin="3" Style="{StaticResource CslaButtonStyle}" /&gt; &lt;Button Content="save" x:Name="SaveButton" IsEnabled="{Binding CanSave}" Margin="3" Style="{StaticResource CslaButtonStyle}" /&gt; &lt;csla:TriggerAction TargetControl="{Binding ElementName=SaveButton}" MethodName="Save"/&gt; &lt;csla:TriggerAction TargetControl="{Binding ElementName=CancelButton}" MethodName="Cancel"/&gt; &lt;/StackPanel&gt; &lt;StackPanel Grid.Row="4" Orientation="Horizontal"&gt; &lt;Rectangle Style="{StaticResource DecoratorRectangle}"/&gt; &lt;Rectangle Style="{StaticResource DecoratorRectangle}"/&gt; &lt;Rectangle Style="{StaticResource DecoratorRectangle}"/&gt; &lt;Rectangle Style="{StaticResource DecoratorRectangle}"/&gt; &lt;/StackPanel&gt; &lt;/Grid&gt; &lt;/Border&gt; &lt;/UserControl&gt; </code></pre> <hr> <p>I believe in order to access the ListItem that is selected in the DataGrid I have to somehow bind the SelectedItem property of the DataGrid to a property in my ViewModel, am I understanding this correctly?</p> <p>I could add something like:</p> <pre><code>SelectedItem="{Binding ViewModel.SelectedListItem}", </code></pre> <p>to the XAML DataGrid element, but I'm still a little unclear what to put for the binding property to actually get it to set the property in my OrderVm.cs...</p> <p>could someone help me with what to put for the Binding? Thanks!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload