Sample taken directly from the Silverlight 4 Toolkit - Samples source code.
We have a style for AutoCompleteBox to make it like a combobox:
<ControlTemplate TargetType="input:AutoCompleteBox">
<Grid Margin="{TemplateBinding Padding}">
...
Click="DropDownToggle_Click">
Now in their example, they have a click event handler in the code behind (indicated below), however I tried to define this method in xaml (i.e. I do not need the code behind the file)
private void DropDownToggle_Click(object sender, RoutedEventArgs e)
{
FrameworkElement fe = sender as FrameworkElement;
AutoCompleteBox acb = null;
while (fe != null && acb == null)
{
fe = VisualTreeHelper.GetParent(fe) as FrameworkElement;
acb = fe as AutoCompleteBox;
}
if (acb != null)
{
if (string.IsNullOrEmpty(acb.SearchText))
{
acb.Text = string.Empty;
}
acb.IsDropDownOpen = !acb.IsDropDownOpen;
}
}
Is it possible?
source
share