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

MetroStatusBar Style and Prism RegionManager #2962

Closed
mxsoftware opened this Issue May 6, 2017 · 3 comments

Comments

Projects
None yet
2 participants
@mxsoftware

mxsoftware commented May 6, 2017

I have problems with the MetroStatusBar style and Prism RegionManager.

When I open a window several times and this window contains a statusbar assigned through Prism RegionManager I get the following messages:

System.Windows.Data Error: 4 : Cannot find source for binding with reference 'RelativeSource FindAncestor, AncestorType='MahApps.Metro.Controls.MetroWindow AncestorLevel='1'.
BindingExpression:Path=WindowTitleBrush; DataItem=null; target element is 'StatusBar' (Name='MxStatusBar'); target property is 'Background' (type 'Brush')

System.Windows.Data Error: 4 : Cannot find source for binding with reference 'RelativeSource FindAncestor, AncestorType='System.Windows.Window', AncestorLevel='1'.
BindingExpression:Path=IsActive; DataItem=null; target element is 'StatusBar' (Name='MxStatusBar'); target property is 'NoTarget' (type 'Object')

I have now resolved by assigning to the statusbar Style = "{x: Null}" and using the following event handler:

    protected override void OnVisualParentChanged(DependencyObject oldParent)
    {
        if (Parent != null)
        {
            Style oStyle = this.FindResource("MetroStatusBar") as Style;
            if (oStyle != null) { MxStatusBar.Style = oStyle; }
        }
        base.OnVisualParentChanged(oldParent);
    }

I think a better solution can be found in:

http://stackoverflow.com/questions/19645660/setting-style-based-on-existence-of-an-ancestor-type

Massimo.

@punker76

This comment has been minimized.

Member

punker76 commented May 9, 2017

@mxsoftware I would like to see this too, so can you create a short sample which demonstrates this issue? Big thx. (I maybe know what I can do to prevent this error)

@punker76 punker76 added this to the 1.6.0 milestone May 9, 2017

@punker76 punker76 self-assigned this May 9, 2017

@mxsoftware

This comment has been minimized.

mxsoftware commented May 10, 2017

It is difficult for me to prepare an example because it is embedded in a complex project.
If it can be helpful, I can test when resolved.
Keep in mind that I have currently been circumventing the problem.
Basically, in the style, you should verify that the Background is extracted from the Ancestor window only if the Ancestor window is different from the null value, the same for the IsActive property of the Ancestor window.
Note that this error message occurs only from the second window opening.
I hope I was helpful.

Massimo.

@punker76 punker76 closed this in 9f75954 Aug 30, 2017

@punker76

This comment has been minimized.

Member

punker76 commented Aug 30, 2017

@mxsoftware This is fixed now and will be available with 1.6.0 (and next 1.6.0-alpha011).

@punker76 punker76 added the Bug label Feb 11, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment