In the Silverlight 4 toolkit example from AutoCompleteBox, how do I switch down to xaml?

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?

+3
source share
2 answers

I replaced the entire line (starting with Click = ...) with the following:

IsChecked="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=IsDropDownOpen, Mode=TwoWay}" 

Now I have eliminated the need for an event handler method.

+1
source

. : PopupOpen PopupClosed. PopupOpen IsDropDownOpen True, PopupClosed - false. DataStateBehaviour IsChecked Property . IsChecked = true = , IsChecked = false =

, .

Blend?

DataStateBehaviour: http://msdn.microsoft.com/en-us/library/ff723952(v=expression.40).aspx http://msdn.microsoft.com/de-de/library/microsoft.expression.interactivity.core.datastatebehavior_members(v=expression.40).aspx http://silverlightforbusiness.net/2010/04/26/using-the-datastatebehavior-for-loading-animations-in-mvvm/

, .

,

EDIT: IsOpen IsChecked . .

0

Source: https://habr.com/ru/post/1788233/


All Articles