KeyDown problem with Silverlight & MVVM
First of all, I am new to the Silverlight + MVVM world. So I will try my best to explain the scenario to you guys.
I have the following AutoCompleteBox in my Silverlight 4 application which works perfect.
<myControls:AutoCompleteBox Name="acbVendorID" MinimumPrefixLength="2"
ItemsSource="{Binding VendorCodes, Mode=TwoWay}"
SelectedItem="{Binding SelectedVendorCode, Mode=TwoWay}"
ValueMemberBinding="{Binding Value}"
cmds:AutoCompletePopulating.Command="{Binding VendorID_Populating}"
cmds:AutoCompletePopulating.CommandParameter="{Binding ElementName=acbVendorID}">
Now my requirement is as follows:
When I select a particular VendorId from the AutoCompleteBox, the rest of the Vendor data should load in a gridview. For this reason, I have implemented the SelectedVendorCode in my ViewModel in the following way:
private KeyValue selectedVendorCode;
public KeyValue SelectedVendorCode
{
get { return selectedVendorCode; }
set
{
if (selectedVendorCode != value)
{
selectedVendorCode = value;
this.NotifyChanged("SelectedVendorCode");
if (selectedVendorCode != null)
{
this.VendorDisplayCode = selectedVendorCode.Value;
OnVendorCodeSelected(); //Sets the vendor collection property bound to the GridView
}
}
}
}
This works fine as well. The problem comes when the user uses the down arrow to browse through the items in AutoCompleteBox, The data in the Grid View gets reloaded as the selected item of the AutoCompleteBox changes.
I want to block this particular functionality. I want the GridView data to be fetched only when the user selects a vendor in the AutoCompleteBox and then presses Enter
I tried to achieve this using the method mentioned in this link
The KeyPressCommand doesn't fire when I use Down Arrow Or The Enter Key. Most other keys seem to开发者_StackOverflow fire this command.
I am a little perplexed by this. Any inputs by you giuys would be really helpful.
Thanks in advance.
~Vinod
Jeff Wilcox has written a post to do just this. The key is to implement a new ISelectionAdapter
and apply to your ListBox
. I have done this in the past and it works great.
精彩评论