SearchResults with Open Customers

Nov 25, 2010 at 10:40 PM

Hi all,

I really enjoyed your latest article on showing us how to create screens like Billy Hollis' famous application.

I am curious as to how would be the best practice for implementing the search results part?  I noticed that the list of Open Customers is tied to the Items collection off of the Conductor.Collection class.  Here is what I did but I am not sure if this is the best approach:

For the Customers section of the HelloScreens project:

I added a name to the Go button so that I could have a method of "PerformSearch" on the CustomersWorkspaceViewModel.cs.

I commented out the TextBlock stating "No matches found and inserted the following Xaml:

<ItemsControl x:Name="SearchItems"
                Grid.Row="1"
                Margin="4 0 0 0">
    <ItemsControl.ItemTemplate>
        <DataTemplate>
            <StackPanel Orientation="Horizontal"
    Margin="4">
                <Button Content="+"
cal:Message.Attach="Edit($dataContext)" />
                <TextBlock Text="{Binding DisplayName, Mode=TwoWay}"
    VerticalAlignment="Center"
    Foreground="White"
    Margin="4 0 0 0" />
            </StackPanel>
        </DataTemplate>
    </ItemsControl.ItemTemplate>
</ItemsControl>

In the CustomersWorkspaceViewModel, I added the following method and property:

public void Go()
{
    var s = string.Empty;
    var vm = createCustomerViewModel();
    vm.DisplayName = "Customer " + count++;
    vm.IsDirty = true;
    SearchItems.Add(vm);
    vm = createCustomerViewModel();
    vm.DisplayName = "Customer " + count++;
    vm.IsDirty = true;
    SearchItems.Add(vm);
    vm = createCustomerViewModel();
    vm.DisplayName = "Customer " + count++;
    vm.IsDirty = true;
    SearchItems.Add(vm);
}

private ObservableCollection<CustomerViewModel> _searchItems = new ObservableCollection<CustomerViewModel>();
public ObservableCollection<CustomerViewModel> SearchItems {
    get { return _searchItems; }
}

Granted, this is test code but I was playing with the idea of getting the search mechanism to work.

Please let me know what is the right way to achieve this?

 

Coordinator
Nov 26, 2010 at 1:20 PM

I'd probably do something pretty similar.

Nov 26, 2010 at 1:33 PM

Thanks Rob.  I just wanted to be sure I was on the right track.