Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Slow startup in VS2017 possibly binding related #291

Open
schragnasher opened this issue May 20, 2018 · 5 comments
Open

Slow startup in VS2017 possibly binding related #291

schragnasher opened this issue May 20, 2018 · 5 comments

Comments

@schragnasher
Copy link

Created a new project in VS2017 community. got it to run, but its seems to hang on startup for a minute before continuing. I do not remember this in 2015.

Once its done spinning i get this output.

System.Windows.Data Error: 4 : Cannot find source for binding with reference 'RelativeSource FindAncestor, AncestorType='System.Windows.Controls.ItemsControl', AncestorLevel='1''. BindingExpression:Path=HorizontalContentAlignment; DataItem=null; target element is 'MenuItemEx' (Name=''); target property is 'HorizontalContentAlignment' (type 'HorizontalAlignment') System.Windows.Data Error: 4 : Cannot find source for binding with reference 'RelativeSource FindAncestor, AncestorType='System.Windows.Controls.ItemsControl', AncestorLevel='1''. BindingExpression:Path=VerticalContentAlignment; DataItem=null; target element is 'MenuItemEx' (Name=''); target property is 'VerticalContentAlignment' (type 'VerticalAlignment') System.Windows.Data Error: 4 : Cannot find source for binding with reference 'RelativeSource FindAncestor, AncestorType='System.Windows.Controls.ItemsControl', AncestorLevel='1''. BindingExpression:Path=HorizontalContentAlignment; DataItem=null; target element is 'MenuItemEx' (Name=''); target property is 'HorizontalContentAlignment' (type 'HorizontalAlignment') System.Windows.Data Error: 4 : Cannot find source for binding with reference 'RelativeSource FindAncestor, AncestorType='System.Windows.Controls.ItemsControl', AncestorLevel='1''. BindingExpression:Path=VerticalContentAlignment; DataItem=null; target element is 'MenuItemEx' (Name=''); target property is 'VerticalContentAlignment' (type 'VerticalAlignment') System.Windows.Data Error: 4 : Cannot find source for binding with reference 'RelativeSource FindAncestor, AncestorType='System.Windows.Controls.ItemsControl', AncestorLevel='1''. BindingExpression:Path=HorizontalContentAlignment; DataItem=null; target element is 'MenuItemEx' (Name=''); target property is 'HorizontalContentAlignment' (type 'HorizontalAlignment') System.Windows.Data Error: 4 : Cannot find source for binding with reference 'RelativeSource FindAncestor, AncestorType='System.Windows.Controls.ItemsControl', AncestorLevel='1''. BindingExpression:Path=VerticalContentAlignment; DataItem=null; target element is 'MenuItemEx' (Name=''); target property is 'VerticalContentAlignment' (type 'VerticalAlignment') System.Windows.Data Error: 4 : Cannot find source for binding with reference 'RelativeSource FindAncestor, AncestorType='System.Windows.Controls.ItemsControl', AncestorLevel='1''. BindingExpression:Path=HorizontalContentAlignment; DataItem=null; target element is 'MenuItemEx' (Name=''); target property is 'HorizontalContentAlignment' (type 'HorizontalAlignment') System.Windows.Data Error: 4 : Cannot find source for binding with reference 'RelativeSource FindAncestor, AncestorType='System.Windows.Controls.ItemsControl', AncestorLevel='1''. BindingExpression:Path=VerticalContentAlignment; DataItem=null; target element is 'MenuItemEx' (Name=''); target property is 'VerticalContentAlignment' (type 'VerticalAlignment') System.Windows.Data Error: 4 : Cannot find source for binding with reference 'RelativeSource FindAncestor, AncestorType='System.Windows.Controls.ItemsControl', AncestorLevel='1''. BindingExpression:Path=HorizontalContentAlignment; DataItem=null; target element is 'MenuItemEx' (Name=''); target property is 'HorizontalContentAlignment' (type 'HorizontalAlignment') System.Windows.Data Error: 4 : Cannot find source for binding with reference 'RelativeSource FindAncestor, AncestorType='System.Windows.Controls.ItemsControl', AncestorLevel='1''. BindingExpression:Path=VerticalContentAlignment; DataItem=null; target element is 'MenuItemEx' (Name=''); target property is 'VerticalContentAlignment' (type 'VerticalAlignment')

@diluculo
Copy link
Contributor

Please see here and here

So, we can remove the warnings as follows:

namespace Gemini.Modules.MainMenu.Views
{
    /// <summary>
    /// Interaction logic for MainMenuView.xaml
    /// </summary>
    public partial class MainMenuView : UserControl
    {
        public MainMenuView()
        {
            InitializeComponent();

#if DEBUG
            System.Diagnostics.PresentationTraceSources.DataBindingSource.Switch.Level = System.Diagnostics.SourceLevels.Critical;
#endif
        }
    }
}

@li0nsar3c00l
Copy link

Instead of just suppressing these warnings, has anyone managed to find te cause for this and fix it?

@BHandle
Copy link

BHandle commented Nov 29, 2018

Found it. I think it's actually related to the control template of the default menu item, which expects to be in an itemscontrol.

In the Gemini project, navigate to Themes->VS2013->Controls->Menu.xaml.

All the way at the bottom you can find the default styles for both the MenuItem and the xcad:MenuItemEx. Simply modify them to force the alignment.

    <!--  Set default styles  -->
    <Style BasedOn="{StaticResource MetroSeparator}" TargetType="Separator" />
    <Style BasedOn="{StaticResource MetroMenuItem}" TargetType="MenuItem">
        <Setter Property="HorizontalContentAlignment" Value="Left" />
        <Setter Property="VerticalContentAlignment" Value="Center" />
    </Style>
    <Style BasedOn="{StaticResource StandardMenu}" TargetType="Menu" />
    <Style BasedOn="{StaticResource MetroContextMenu}" TargetType="ContextMenu" />
    <Style BasedOn="{StaticResource MetroContextMenu}" TargetType="xcad:ContextMenuEx" />
    <Style BasedOn="{StaticResource MetroMenuItem}" TargetType="xcad:MenuItemEx">
        <Setter Property="HorizontalContentAlignment" Value="Left" />
        <Setter Property="VerticalContentAlignment" Value="Center" />
    </Style>

@ryanvs
Copy link
Contributor

ryanvs commented Jun 29, 2020

My guess is the performance slowdown is actually related to MEF. In particular, you might add timing information to AppBootstrapper.Configure to check how long it takes to load MEF. For comparison, I assume Visual Studio caches MEF information to improve loading time, although occasionally you see the "Updating MEF Components" busy dialog during startup. Once Configure and MEF is finished loading, then I think the UI starts and you would start seeing the binding warnings.

@kornman00
Copy link
Contributor

I'm using the latest Nuget and didn't want to branch the code just to fix this (still need to figure out the unnamed "Resource not found" warnings). Was able to figure out a fix for the MetroMenuItem errors by adding the code below to my App.xaml.

<Application
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:gemini="http://schemas.timjones.io/gemini"
             xmlns:xcad="http://schemas.xceed.com/wpf/xaml/avalondock">
    <Application.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary>
                    <gemini:AppBootstrapper x:Key="bootstrapper" />
                </ResourceDictionary>

                <!-- Fix based on https://github.com/tgjones/gemini/issues/291#issuecomment-443011486
                    Basically hack in the fix to Geimini resources to inhibit WPF from spewing about 10 Error traces on startup:
                    System.Windows.Data Error: Cannot find source for binding with reference 'RelativeSource FindAncestor, AncestorType='http://System.Windows.Controls.ItemsControl', AncestorLevel='1''. BindingExpression:Path=HorizontalContentAlignment; DataItem=null; target element is 'MenuItemEx' (Name=''); target property is 'HorizontalContentAlignment' (type 'HorizontalAlignment')
                    System.Windows.Data Error: Cannot find source for binding with reference 'RelativeSource FindAncestor, AncestorType='http://System.Windows.Controls.ItemsControl', AncestorLevel='1''. BindingExpression:Path=VerticalContentAlignment; DataItem=null; target element is 'MenuItemEx' (Name=''); target property is 'VerticalContentAlignment' (type 'VerticalAlignment')
                -->
                <ResourceDictionary Source="pack://application:,,,/Gemini;component/Themes/VS2013/Controls/Menu.xaml">
                    <Style BasedOn="{StaticResource MetroMenuItem}" TargetType="MenuItem" x:Key="MetroMenuItemFix">
                        <Setter Property="HorizontalContentAlignment" Value="Left" />
                        <Setter Property="VerticalContentAlignment" Value="Center" />
                    </Style>
                    <Style BasedOn="{StaticResource MetroMenuItem}" TargetType="xcad:MenuItemEx" x:Key="MetroMenuItemExFix">
                        <Setter Property="HorizontalContentAlignment" Value="Left" />
                        <Setter Property="VerticalContentAlignment" Value="Center" />
                    </Style>
                </ResourceDictionary>
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </Application.Resources>
</Application>

kornman00 added a commit to kornman00/gemini that referenced this issue Sep 13, 2020
Based on the recommendation by @BHandle here tgjones#291 (comment)

Avoids WPF generating traces like:
System.Windows.Data Error: 4 : Cannot find source for binding with reference 'RelativeSource FindAncestor, AncestorType='System.Windows.Controls.ItemsControl', AncestorLevel='1''. BindingExpression:Path=HorizontalContentAlignment; DataItem=null; target element is 'MenuItemEx' (Name=''); target property is 'HorizontalContentAlignment' (type 'HorizontalAlignment')
System.Windows.Data Error: 4 : Cannot find source for binding with reference 'RelativeSource FindAncestor, AncestorType='System.Windows.Controls.ItemsControl', AncestorLevel='1''. BindingExpression:Path=VerticalContentAlignment; DataItem=null; target element is 'MenuItemEx' (Name=''); target property is 'VerticalContentAlignment' (type 'VerticalAlignment')

Note: VS2019 seems to have removed the UTF8 BOM header and the file is now strictly ANSI
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants