/// Called from <see cref="OnApplyTemplate"/> private void OnApplyTemplateAutoSuggestBox(AutoSuggestBox auto) { if (_autoSuggestBox != null) { _autoSuggestBox.Loaded -= OnASBLoaded; _autoSuggestBox.QuerySubmitted -= AutoSuggestBox_QuerySubmitted; _autoSuggestBox.SuggestionChosen -= AutoSuggestBox_SuggestionChosen; _autoSuggestBox.TextChanged -= AutoSuggestBox_TextChanged; _autoSuggestBox.PointerEntered -= AutoSuggestBox_PointerEntered; _autoSuggestBox.PointerExited -= AutoSuggestBox_PointerExited; _autoSuggestBox.PointerCanceled -= AutoSuggestBox_PointerExited; _autoSuggestBox.PointerCaptureLost -= AutoSuggestBox_PointerExited; _autoSuggestBox.GotFocus -= AutoSuggestBox_GotFocus; _autoSuggestBox.LostFocus -= AutoSuggestBox_LostFocus; // Remove any previous QueryIcon _autoSuggestBox.QueryIcon = null; } _autoSuggestBox = auto; if (_autoSuggestBox != null) { _autoSuggestBox.Loaded += OnASBLoaded; _autoSuggestBox.QuerySubmitted += AutoSuggestBox_QuerySubmitted; _autoSuggestBox.SuggestionChosen += AutoSuggestBox_SuggestionChosen; _autoSuggestBox.TextChanged += AutoSuggestBox_TextChanged; _autoSuggestBox.PointerEntered += AutoSuggestBox_PointerEntered; _autoSuggestBox.PointerExited += AutoSuggestBox_PointerExited; _autoSuggestBox.PointerCanceled += AutoSuggestBox_PointerExited; _autoSuggestBox.PointerCaptureLost += AutoSuggestBox_PointerExited; _autoSuggestBox.GotFocus += AutoSuggestBox_GotFocus; _autoSuggestBox.LostFocus += AutoSuggestBox_LostFocus; // Setup a binding to the QueryIcon of the Parent if we're the last box. if (Content is PretokenStringContainer str && str.IsLast) { var iconBinding = new Binding() { Source = Owner, Path = new PropertyPath(nameof(Owner.QueryIcon)), RelativeSource = new RelativeSource() { Mode = RelativeSourceMode.TemplatedParent } }; var iconSourceElement = new IconSourceElement(); iconSourceElement.SetBinding(IconSourceElement.IconSourceProperty, iconBinding); _autoSuggestBox.QueryIcon = iconSourceElement; } } }
protected override void OnApplyTemplate() { _alternateCloseButton = GetTemplateChild <Button>("AlternateCloseButton"); _actionButton = GetTemplateChild <Button>("ActionButton"); _title = GetTemplateChild <TextBlock>("Title"); _message = GetTemplateChild <TextBlock>("Message"); _hyperlinkButton = GetTemplateChild <HyperlinkButton>("HyperlinkButton"); _standardIcon = GetTemplateChild <IconSourceElement>("StandardIcon"); _userIcon = GetTemplateChild <IconSourceElement>("UserIcon"); _contentRootGrid = GetTemplateChild <Grid>("ContentRootGrid"); UpdateButtonsState(); UpdateSeverityState(); OnIsOpenChanged(); UpdateMargins(); _alternateCloseButton.Click += new RoutedEventHandler(OnCloseButtonClick); _actionButton.Click += (s, e) => ActionButtonClick?.Invoke(s, e); }
/// Called from <see cref="OnApplyTemplate"/> private void OnApplyTemplateAutoSuggestBox(AutoSuggestBox auto) { if (_autoSuggestBox != null) { _autoSuggestBox.Loaded -= OnASBLoaded; _autoSuggestBox.QuerySubmitted -= AutoSuggestBox_QuerySubmitted; _autoSuggestBox.SuggestionChosen -= AutoSuggestBox_SuggestionChosen; _autoSuggestBox.TextChanged -= AutoSuggestBox_TextChanged; _autoSuggestBox.PointerEntered -= AutoSuggestBox_PointerEntered; _autoSuggestBox.PointerExited -= AutoSuggestBox_PointerExited; _autoSuggestBox.PointerCanceled -= AutoSuggestBox_PointerExited; _autoSuggestBox.PointerCaptureLost -= AutoSuggestBox_PointerExited; _autoSuggestBox.GotFocus -= AutoSuggestBox_GotFocus; _autoSuggestBox.LostFocus -= AutoSuggestBox_LostFocus; // Remove any previous QueryIcon _autoSuggestBox.QueryIcon = null; } _autoSuggestBox = auto; if (_autoSuggestBox != null) { _autoSuggestBox.Loaded += OnASBLoaded; _autoSuggestBox.QuerySubmitted += AutoSuggestBox_QuerySubmitted; _autoSuggestBox.SuggestionChosen += AutoSuggestBox_SuggestionChosen; _autoSuggestBox.TextChanged += AutoSuggestBox_TextChanged; _autoSuggestBox.PointerEntered += AutoSuggestBox_PointerEntered; _autoSuggestBox.PointerExited += AutoSuggestBox_PointerExited; _autoSuggestBox.PointerCanceled += AutoSuggestBox_PointerExited; _autoSuggestBox.PointerCaptureLost += AutoSuggestBox_PointerExited; _autoSuggestBox.GotFocus += AutoSuggestBox_GotFocus; _autoSuggestBox.LostFocus += AutoSuggestBox_LostFocus; // Setup a binding to the QueryIcon of the Parent if we're the last box. if (Content is PretokenStringContainer str && str.IsLast) { // Workaround for https://github.com/microsoft/microsoft-ui-xaml/issues/2568 if (Owner.QueryIcon is FontIconSource fis && fis.ReadLocalValue(FontIconSource.FontSizeProperty) == DependencyProperty.UnsetValue) { // This can be expensive, could we optimize? // Also, this is changing the FontSize on the IconSource (which could be shared?) fis.FontSize = Owner.TryFindResource("TokenizingTextBoxIconFontSize") as double? ?? 16; } var iconBinding = new Binding() { Source = Owner, Path = new PropertyPath(nameof(Owner.QueryIcon)), RelativeSource = new RelativeSource() { Mode = RelativeSourceMode.TemplatedParent } }; var iconSourceElement = new IconSourceElement(); iconSourceElement.SetBinding(IconSourceElement.IconSourceProperty, iconBinding); _autoSuggestBox.QueryIcon = iconSourceElement; } } }