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 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);
}
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)