Custom window chrome binding issue.

Topics: Conventions, Framework Services
Jul 28, 2013 at 6:29 PM
Hi All

I have a custom WindowManager that overrides EnsureWindow and creates the custom window, when using this ViewModelBinder no longer finds any elements with names to apply the conventions.

I've done some digging and comparison between using WPF and custom windows and found that in BindingScope.FindNamedDescendants() line 114 ReferenceEquals() finds that my user control is not equal to the routeHops.Root and therefor kicks out of the loop and doesn't continue down the visual tree to find any more elements.

Anyone have any ideas as to why this is happening?

Many Thanks

Ben

EnsureWindow() code for reference
protected override System.Windows.Window EnsureWindow(object model, object view, bool isDialog) {
    var window = view as FirstFloor.ModernUI.Windows.Controls.ModernWindow;
    if (window == null) {
        window = new FirstFloor.ModernUI.Windows.Controls.ModernWindow {
            Content = view,
            SizeToContent = System.Windows.SizeToContent.WidthAndHeight,
            Style = (System.Windows.Style)App.Current.Resources["EmptyWindow"]
        };
        var owner = InferOwnerOf(window);
        if (owner != null) {
            window.WindowStartupLocation = System.Windows.WindowStartupLocation.CenterOwner;
            window.Owner = owner;
        } else {
            window.WindowStartupLocation = System.Windows.WindowStartupLocation.CenterScreen;
        }
    } else {
        var owner = InferOwnerOf(window);
        if (owner != null && isDialog) {
            window.Owner = owner;
        }
    }
    return window;
}
Jul 29, 2013 at 12:55 AM
Found my problem...
After taking a break from tearing my hair out I took another look at the framework's implementation of WindowManager and found I was missing a single line of code.
window.SetValue(View.IsGeneratedProperty, true);
Adding this after creating the window fixed the issues.

So simple..