ItemsControl will not re-display after popup

I have an ItemsControl in a window, one of the columns of which contains a simple very narrow StackPanel, which serves as a Target for a Popup that appears under certain circumstances.

After it has been shown and the user has been informed about something, the user closes this pop-up using a button (the command attached to this button simply sets the property of the view model that Popup.IsOpen is attached to false ).

The popup closes, but its image remains captured on the ItemsControl until it scrolls, or another window does not overlap it.

How to recolor ItemsControl after closing popup ?

the code:

1) ItemsControl

<ScrollViewer ...> <ItemsControl x:Name="ux_List" ItemTemplate="{DynamicResource Lib_ItemTemplate}" ItemsSource="{Binding Path=TemplateInfos,Mode=OneWay}" AlternationCount="2" ... /> 

2) Element template

 <DataTemplate x:Key="Lib_ItemTemplate"> <Grid x:Name="grid"> ... <StackPanel Grid.Column="1"> <Popup IsOpen="{Binding Path=HasError,Mode=OneWay}"> <ContentPresenter Content="{Binding Path=ErrorContext, Mode=OneWay}" 

and next to it in the last line of the fragment is a close button.

 <Button ... Command="{TemplateBinding CloseButtonCommand}" /> 

The command is attached to this button, implemented as follows:

 private void OnCloseErrorMessageCommand() { HasError = false; ... } 
+4
source share
3 answers

Here is my work site:

In the parental control window:

  public IntPtr Hwnd { get; set; } protected override void OnSourceInitialized(EventArgs e) { base.OnSourceInitialized(e); IntPtr hwnd = new WindowInteropHelper(this).Handle; this.Hwnd = hwnd; } public void Refresh() { if (Hwnd == IntPtr.Zero) throw new InvalidOperationException("Hwnd"); InvalidateRect(this.Hwnd, IntPtr.Zero, true); } [DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)] public static extern bool InvalidateRect(IntPtr hWnd, IntPtr rect, bool erase); 

After closing the pop-up window, the Refresh () call method.

+2
source

When the popup closes, what happens if you set Visibility = Collapsed? It seems like it pretty well removes it from sight completely.

Otherwise, I don’t know how to delete one element, and the ItemsControl.Refresh method will reload all your elements (and, as a rule, lead to goofyness display (elements disappear and reappear, animations reset, etc.).

0
source

It's hard to guess what prevents redrawing your ItemsControl after closing the popup. Usually this does not happen.

One thing you can always do is call InvalidateVisual or InvalidateArrange in the ItemsControl. This forces a completely new layout / rendering cycle.

0
source

Source: https://habr.com/ru/post/1393992/


All Articles