Skip to content
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

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

Open
walterlv opened this issue Jul 12, 2019 · 0 comments

Comments

@walterlv
Copy link
Contributor

commented Jul 12, 2019

  • .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
  2. The Grid contains a Rectangle and a TextBlock and the Rectangle will change its visibility period.

The layout

Actual behavior:

The Border VisualBrush will not refresh its layout.

2019-07-12-visual-layout-not-refresh-2

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

Expected behavior:

The VisualBrush will refresh the layout.

Minimal repro:

This is the whole XAML file:

<Window x:Class="Walterlv.Demo.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="Walterlv 的 WindowChrome 示例窗口" Height="450" Width="800"
        WindowStartupLocation="CenterScreen">
    <Grid>
        <Grid x:Name="VisualSource">
            <Rectangle x:Name="VisibleOr" Fill="LightCoral" Visibility="Visible" />
            <TextBlock FontSize="24" TextAlignment="Center" VerticalAlignment="Center">
                <Run Text="I'm walterlv, " />
                <LineBreak />
                <Run Text="I'm reproducing this Visual bug." />
            </TextBlock>
        </Grid>
        <Border>
            <Border.Background>
                <VisualBrush Visual="{Binding Source={x:Reference VisualSource}}" />
            </Border.Background>
        </Border>
    </Grid>
</Window>

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

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

@grubioe grubioe added this to the Future milestone Jul 15, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.