0

I made an application in WPF (on .NET 5.0 with MVVM) and used an OpenCloseWindowBehavior I've found on stackoverflow to open three different windows.

On every PC in my company this works fine. But on the PCs of my customer there is a problem with one of these windows (ScalingWindow): When he opens it, the whole window is transparent but the buttons and textboxes appear when he hovers with the mouse over them. He can make the whole window look normal by pushing it outside of the screen edge and pulling it back into.

How it should look

How it looks directly after opening

How it looks after hovering over it

MainView:

<i:Interaction.Behaviors>
    <local:OpenCloseWindowBehavior WindowType="local:CommunicationWindow" Open="{Binding IsCommunicationOpen, Mode=TwoWay}" Context="{Binding Communication}"/>
    <local:OpenCloseWindowBehavior WindowType="local:ScalingWindow" Open="{Binding IsScalingOpen, Mode=TwoWay}" Context="{Binding Scaling}"/>
    <local:OpenCloseWindowBehavior WindowType="local:AboutWindow" Open="{Binding IsAboutOpen, Mode=TwoWay}"/>
</i:Interaction.Behaviors>

ViewModel:

private CommunicationViewModel _communication;
public CommunicationViewModel Communication
{
    get => _communication;
    set => SetProperty(ref _communication, value);
}
private ScalingViewModel _scaling;
public ScalingViewModel Scaling
{
    get => _scaling;
    set => SetProperty(ref _scaling, value);
}

private bool _isCommunicationOpen;
public bool IsCommunicationOpen
{
    get => _isCommunicationOpen;
    set
    {
        if (value)
        {
            Communication = new(_measurementFlat.Connection);
        }
        else
        {
            Communication.Dispose();
            Communication = null;
        }
        SetProperty(ref _isCommunicationOpen, value);
    }
}

private bool _isScalingOpen;
public bool IsScalingOpen
{
    get => _isScalingOpen;
    set
    {
        if (value)
        {
            Scaling = new(_measurementFlat.Scaling);
        }
        else
        {
            Scaling.Dispose();
            Scaling = null;
        }
        SetProperty(ref _isScalingOpen, value);
    }
}

private bool _isAboutOpen;
public bool IsAboutOpen
{
    get => _isAboutOpen;
    set => SetProperty(ref _isAboutOpen, value);
}

Publish Settings

My problem is that I have no clue where the fault could be and I can't reproduce it. Maybe someone of you knows something about this issue.

One thing I tried, is to reload the window in the behavior directly after opening it. I did this by inserting window.InvalidateVisual();.

private static void OnOpenChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
    var me = (OpenCloseWindowBehavior)d;
    if ((bool)e.NewValue)
    {
        object instance = Activator.CreateInstance(me.WindowType);
        if (instance is Window window)
        {
            window.Closing += (s, ev) =>
            {
                if (me.Open)
                {
                    me._windowInstance = null;
                    me.Open = false;
                }
            };
            if (me.Context != null)
            {
                window.DataContext = me.Context;
            }
            window.Show();
            me._windowInstance = window;
            window.InvalidateVisual();
        }
        else
        {
            throw new ArgumentException(string.Format("Type '{0}' does not derive from System.Windows.Window.", me.WindowType));
        }
    }
    else
    {
        if (me._windowInstance != null)
            me._windowInstance.Close();
    }
}

But according to my customer, this didn't change anything.

Thanks for your help and please tell me if something is missing or I did something wrong (its my first post here)

LuP1999
  • 1
  • 1
  • _I made an application in WPF (on .NET 5.0 with MVVM)_: According to [.NET Lifecycle](https://learn.microsoft.com/en-us/lifecycle/products/microsoft-net-and-net-core) _.NET 5_ is no longer supported which means that it should not be used on any customer PC. If using Visual Studio for development, for .NET versions >= 6 require at least VS 2022. – Tu deschizi eu inchid May 25 '23 at 15:16
  • Start by finding out the OS version your customer is using and whether or not any Windows themes have been set. Also find out what the Windows scaling setting is. – Tu deschizi eu inchid May 25 '23 at 15:22
  • @Tudeschizieuinchid I built it now on .NET 7 but it'll take some time to check it out. Cause my customer is in holidays – LuP1999 May 31 '23 at 06:06

0 Answers0