How we make the search efficent in combobox if it is editable? - wpf

<ComboBox Name="cbDesignation" IsEditable="True" TextSearch.TextPath="DesignationName"
StaysOpenOnEdit="True" ItemsSource="{Binding Path=DesignationCollection,Mode=TwoWay}"
SelectedItem="{Binding Path=SelectedDesignation,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged,ValidatesOnDataErrors=True}"
VerticalAlignment="Center">
<ComboBox.ItemsPanel>
<ItemsPanelTemplate>
<VirtualizingStackPanel/>
</ItemsPanelTemplate>
</ComboBox.ItemsPanel>
<ComboBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Path=DesignationName}" VerticalAlignment="Center" Grid.Column="1" Margin="5,0,0,0"/>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
If it is editable then it search but only one item I want that whrn user enter start of alphabet then it will show all the list regardin this alphabet

How about an AutoComplete TextBox instead? It also uses suggestions and does all the filtering for you. You can find one here:
http://wpfactb.codeplex.com/
(more info here: http://blogs.windowsclient.net/dragonz/archive/2010/02/23/autocomplete-textbox-control-for-wpf.aspx)

Related

The tapped on comboBox work incorrectly

I have comboBox with names list . When I try to select a name in the list, it generally takes 3-5 clicks on the selected name.
<ComboBox
Grid.Row="6"
Height="50"
Margin="0,20,0,0"
Name="AssetClassComboBox"
HorizontalAlignment="Stretch"
ScrollViewer.VerticalScrollBarVisibility="Hidden"
ItemsSource="{x:Bind ListAssetClass, Mode=OneWay}">
<ComboBox.ItemTemplate>
<DataTemplate x:DataType="models:ComboBoxAssetClassItem">
<ComboBoxItem Content="{x:Bind Name}"/>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
If I delete this code the comboBox works correctly, the list is visible, but I cannot see the names.
<ComboBox.ItemTemplate>
<DataTemplate x:DataType="models:ComboBoxAssetClassItem">
<ComboBoxItem Content="{x:Bind Name}"/>
</DataTemplate>
</ComboBox.ItemTemplate>
Instead of creating a ItemTemplate you could simply use the property DisplayMemberPath of ComboBox:
<ComboBox
...
DisplayMemberPath="Name"
ItemsSource="{x:Bind ListAssetClass, Mode=OneWay}">

Turning off ComboBox loop scroll

I have a ComboBox to let the user choose from a list, but when the list gets long enough it begins to automatically wrap around. For example, if the user scrolls far enough down they'll reach the end of the list and then find the top of the list just after a single blank row. The drop down selection list never really ends, it just keeps looping forever.
How can I remove this looping scroll feature so the user just reaches the end of list?
My code:
<ComboBox Name="listSelect" ItemsSource="{Binding DataInstance.ItemList}">
<ComboBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding ItemNumber, Mode=OneWay}" />
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
Possible solution from this article: http://netitude.bc3tech.net/2013/04/12/windows-8s-combobox-and-the-carouselpanel/
Set this to your ComboBox control, this should overwrite the default panel:
<ComboBox.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Vertical" />
</ItemsPanelTemplate>
</ComboBox.ItemsPanel>
This is to edit the panel template, so your final code will be:
<ComboBox Name="listSelect" ItemsSource="{Binding DataInstance.ItemList}">
<ComboBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding ItemNumber, Mode=OneWay}" />
</DataTemplate>
</ComboBox.ItemTemplate>
<ComboBox.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Vertical" />
</ItemsPanelTemplate>
</ComboBox.ItemsPanel>
</ComboBox>

WPF - adding user control to listbox

I am trying to add a usercontrol to a ListBox.
My usercontrol contains a collection of basic elements like textbox and dropdowns, in a fashion so that it creates a row of elements.
The code for ListBox in my main window is as -
<GroupBox FontWeight="SemiBold" Foreground="#FF0CAEF9" Name="gbAddProducts" Style="{x:Null}" Header="ADD PRODUCTS" HorizontalAlignment="Left" Margin="0,256,0,0" VerticalAlignment="Top" Width="990" Height="207">
<ListBox Name="lstboxAddProduct" ItemsSource="{Binding Path=AddNewProductRowViewModelList, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True}" BorderThickness="0" Margin="0,10,-2,23">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Vertical">
<ContentControl Content="{Binding AddNewProductRowViewModel}" />
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
<Validation.ErrorTemplate>
<ControlTemplate>
<StackPanel>
<AdornedElementPlaceholder x:Name="aepForError"/>
<ItemsControl ItemsSource="{Binding}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding ErrorContent}" Foreground="White" Background="#DC000C" />
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</StackPanel>
</ControlTemplate>
</Validation.ErrorTemplate>
</ListBox>
</GroupBox>
Here AddNewProductRowViewModelList is my user control list containing 5 controls.
The Problem that I see is that when I run the code, the screen has 5 rows, ie I can click on the area to figure out theer are 5 rows as that section gets highlighted. But they are not visible.
Could it be some 'bring to front' sort of issue.
Please advise.
Thanks in advance.
I would do it this way instead:
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Vertical">
<ContentControl>
<local:AddNewProductRowView Datacontext="{Binding AddNewProductRowViewModel}"/>
</ContentControl>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>

VirtualizingStackPanel is working fine in ListView's ItemPanel. But not the simple StackPanel

I just want to display Items in ListView like windows explorer (Large icons). For the same I used the below code.
<ListView Name="lstView" ItemsSource="{Binding MovieList}" >
<ListView.ItemsPanel>
<ItemsPanelTemplate>
<!-- <VirtualizingStackPanel/> --> <!-- Working Fine -->
<StackPanel/> <!-- Items are not displayed -->
<!-- It must be wrap panel -->
<!-- OK, lets see with simple -->
</ItemsPanelTemplate>
</ListView.ItemsPanel>
<ListView.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<Label Content="{Binding Path}" />
</StackPanel>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
In the above code, If I use VirtualizingStackPanel then the items are displayed fine, but one by one which I don't want. If I use StackPanel, the items are not dispalyed in screen, even the items are not added in StackPanel. I checked with Snoop tool.
I should use WrapPanel instread of StackPanel to list items, but lets see the simple StackPanel.
Why the items are not displayed in StackPanel?
Basically I want list the items like WindowExplorer large icon view.
I am using .NET 4.0
I tried same thing in my code and it's working fine. Virtualization works as long as size of the ItemsControl's viewport is restricted.
just try replacing the code given below:
<ListView ItemsSource="{Binding Movies}" Width="400" HorizontalAlignment="Left" >
<ListView.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel VirtualizingPanel.IsVirtualizing="True" />
</ItemsPanelTemplate>
</ListView.ItemsPanel>
<ListView.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Vertical">
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding Year}" FontSize="12" Margin="10,0,0,0"/>
<TextBlock Text="{Binding Name}" FontSize="12" Margin="10,0,0,0"/>
</StackPanel>
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding Category}" FontSize="12" Margin="10,0,0,0"/>
<TextBlock Text="{Binding Director}" FontSize="12" Margin="10,0,0,0"/>
</StackPanel>
</StackPanel>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>

MVVM WPF Creating Child Elements

I have a Customer object which has a List of Orders. Now, using MVVM pattern I am displaying a list of customers which is part of the CustomerOrderViewModel and "CustomerOrderView". The customers are shown using a listbox as implemented below:
<ListBox BorderThickness="0" Grid.Column="0" Grid.Row="0" ItemsSource="{Binding Path=Customers}">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel>
<view:CustomerView />
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
Now I also need to display the orders but I need to display it outside the ListBox. Like this:
<StackPanel Grid.Column="1" Grid.Row="0" Margin="10">
<ItemsControl ItemsSource="{Binding Path=Orders}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Path=Name}" />
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</StackPanel>
This does not work because There is no property on CustomerOrderViewModel for Orders. The Orders is a collection on the Customer object. How can I achieve it?
Here is the updated example:
<ListBox BorderThickness="0" Grid.Column="0" Grid.Row="0" ItemsSource="{Binding Path=Customers}">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<view:CustomerView />
<StackPanel Margin="20">
<ItemsControl ItemsSource="{Binding Path=Orders}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<view:OrderView />
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</StackPanel>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
I don't want to display the orders for all the customers. I just want to display the order of the currently selected customer.
You could use a master-detail binding.
I would suggest you to add an additional List to your window and bind its DataContext to the currently selected customer in your ListBox. It will be something like that:
<ListBox BorderThickness="0" Grid.Column="0" Grid.Row="0"
ItemsSource="{Binding Path=Customers}"
x:Name="CustomerList">
<ListBox.ItemTemplate>
<DataTemplate>
<view:CustomerView />
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
<ListBox Grid.Column="1" Grid.Row="0" DataContext="{Binding ElementName=CustomersList, Path=SelectedItem}">
<ListBox.ItemTemplate>
<DataTemplate>
<view:Order DataContext="{Binding Path=Orders}" />
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>

Resources