WPF – Binding ListBox SelectedItems – Attached Property VS Style

2 בMay 2014

It seems List Box doesn’t support SelectedItems property Binding. Well since my application does support multiple items selection, I went looking for a solution. What I found was the following: Support Multiple Selection Using Style Add the following style in the listbox’s XAML: <ListBox.ItemContainerStyle>                               <Style TargetType="{x:Type ListBoxItem}">                                   <Setter Property="IsSelected" Value="{Binding Mode=TwoWay, Path=IsSelected}"/>                               </Style>                           </ListBox.ItemContainerStyle> Add support for the styling in the view model: We have to support the style by wrapping the original AnimalType class. publicclassAnimalTypeForView       {           publicbool IsSelected { get; set; }           publicAnimalType Type { get; set; }       }       publicList<AnimalType> AnimalTypes       {           get { return AnimalTypes; }           set           {               _AnimalTypes =value;               NotifyOfPropertyChange(() => _AnimalTypes);           }       } I don’t like that, since it adds noise and mess to the view model code and it...
6 comments

Create A Visual Studio Template Project With Refrenced Nugget

1 בMay 2014

I was repeating the task of creating a MVVM application, mostly to test complicated XAML scenarios in an isolated environment outside my real application, and thought it would be easier to use a VS template project for that. In order to use a template project, you need to export your project and pack it as a VS extension, with a special treat to referenced nuggets. 1. Download VS SDK. Will open the ability to create a VS extension project. 2. Create a VS Extension. Straight forward steps to export and pack as an extension. 3. Handle Nuggets. If you project contains Nuggets, you need to...
no comments

SQL – Create and use a stored procedure with table as a parameter

29 בApril 2014

Using SQL Server 2012 Assuming we have a sample "TestDB" with the following scheme: Create a type which will use for the input parameter: Create a new stored procedure Fill in the stored procedure name, the parameter name and the query Notice the CostumersIDs is the parameter name and CostumersIdsType is it's type which we created earlier. For simplicity, the query I used just returns the received input parameter. Test the stored procedure in sql server: What happened here is: - We created a temporary table of our declared type (CostumersIdsType), and inserted into it a few value. - Called our stored procedure with the temporary table as a...
tags: , ,
no comments