Sample taken straight from the Silverlight 4 Toolkit - Samples source code.
We have a style for the AutoCompleteBox to make it like a combobox :
<ControlTemplate TargetType="input:AutoCompleteBox">
<Grid Margin="{TemplateBinding Padding}">
...
Click="DropDownToggle_Click">
Now, in their sample, they have a click event handler in code behind (listed below), however I was trying to define this method in the xaml ( i.e. I don't want a code behind 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 this possible ?
I have replaced the whole line (starting with Click=...), with the following;
IsChecked="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=IsDropDownOpen, Mode=TwoWay}"
I have eliminated the need now for the event handler method.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With