dotnet / dotnet/wpf

The VisualBrush only refresh the visual but not the layout when the Visual visibility changes

Open
#1,241 0 comments 3 reactions 0 assignees View on GitHub
.NET Framework Bug
Dominant language
C#
Stars
7.7k
Forks
1.3k
Avg merge
1d 11h
Merged PRs (30d)
61

Description

* .NET Core Version: 3.0 Preview6
* Windows version: Windows 10.0.18932.1000
* Does the bug reproduce also in WPF for .NET Framework 4.8?: Yes



**Problem description:**

1. We have a `Border` to show a `VisualBrush` of another `Grid`
1. The `Grid` contains a `Rectangle` and a `TextBlock` and the `Rectangle` will change its visibility period.

![The layout](https://user-images.githubusercontent.com/9959623/61129066-316a6380-a4e6-11e9-8bd1-7921441b3fe3.png)

**Actual behavior:**

The `Border` `VisualBrush` will not refresh its layout.

![2019-07-12-visual-layout-not-refresh-2](https://user-images.githubusercontent.com/9959623/61129220-8312ee00-a4e6-11e9-976a-a42269cb3375.gif)

But if we set the initial visibility of the `Rectangle` to `Collapsed`, we'll find that the initial `VisualBrush` shows the correct state.

![The running behavior](https://user-images.githubusercontent.com/9959623/61128929-d2a4ea00-a4e5-11e9-90f9-231c79f2c6ad.gif)

**Expected behavior:**

The `VisualBrush` will refresh the layout.

**Minimal repro:**

This is the whole XAML file:

```xml















```

This is the code-behind. Notice that it changes the visibility of the `Rectangle` every 1 second.

```csharp
using System.Threading.Tasks;
using System.Windows;

namespace Walterlv.Demo
{
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
Loaded += OnLoaded;
}

private async void OnLoaded(object sender, RoutedEventArgs e)
{
while (true)
{
await Task.Delay(1000);
VisibleOr.Visibility = Visibility.Collapsed;
await Task.Delay(1000);
VisibleOr.Visibility = Visibility.Visible;
}
}
}
}
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.