/// <summary>
        ///     Checks if the edgecases (currently just Datagrid) acctually need to be handled and corrects
        ///     <paramref name="senderObject" />, if necessary.
        ///     Since DataGridHeaders were not individually handled in
        ///     <see cref="LocalizerEventHandler" />, they are handled here.
        /// </summary>
        /// <param name="senderObject">
        ///     The object that triggered the MouseEvent.
        ///     If it is a DataGrid it will be exchanged for the DataGridHeader that was clicked.
        /// </param>
        /// <param name="eventArgs">EventArgs received by event handler.</param>
        /// <returns>
        ///     True if correct element was clicked. False, if this event is not meant to be handled.
        /// </returns>
        private static bool CorrectElementWasClicked(ref object senderObject, MouseButtonEventArgs eventArgs)
        {
            if (senderObject is DataGrid)
            {
                //find the DataGridColumnHeader that was originally clicked
                //use the VisualTree, as Headers aren't found in the LogicalTree.
                //eventArgs.OriginalSource can be cast to DepencyObject, as
                //FindVisualParent returns null in that case.
                var columnHeader =
                    VisualTreeUtils.FindVisualParent <DataGridColumnHeader>(
                        eventArgs.OriginalSource as DependencyObject);

                if (columnHeader == null)
                {
                    //Header wasn't clicked.
                    return(false);
                }

                senderObject = columnHeader;

                return(true);
            }

            //if senderObject is not considered edgecase, it will be assumed to be correct.
            return(true);
        }
Esempio n. 2
0
        public override DataTemplate SelectTemplate(object item, DependencyObject container)
        {
            FrameworkElement element = container as FrameworkElement;

            TabbedExpanderView tabbedExpander = VisualTreeUtils.FindVisualParent <TabbedExpanderView>(element);

            if (tabbedExpander.Items.Count == 1)
            {
                return(Application.Current.Resources["ExpanderHeaderItemStyle"] as DataTemplate);
            }
            else
            {
                return(Application.Current.Resources["ExpanderHeaderItemsStyle"] as DataTemplate);
            }

            //return null;
        }