Note that there are some explanatory texts on larger screens.

plurals
  1. POForcing a ItemsControl panel to repaint
    primarykey
    data
    text
    <p>Alright, I have a ListBox that holds container controls. Each container control contains 1-X widgets and these widgets are laid out in a completely custom WrapPanel and it's working great. The size of the widgets is determined/updated from 2 factors:</p> <ol> <li>The size of the parent listbox (updated if changed)</li> <li>A view scale SliderBar (25%, 50%, 100%) - like a zoom button</li> </ol> <p>If the listbox size is changed, the custom panel repaints and sizes of widgets are adjusted accordingly in my code. Working perfect.</p> <pre><code> &lt;Grid.RowDefinitions&gt; &lt;RowDefinition Height="*" /&gt; &lt;RowDefinition Height="5" /&gt; &lt;RowDefinition Height="Auto" /&gt; &lt;/Grid.RowDefinitions&gt; &lt;ListBox Name="lstGroups" Grid.Column="0" ItemsSource="{Binding Path=TopLevelGroups}" BorderThickness="0" ScrollViewer.VerticalScrollBarVisibility="Hidden" SizeChanged="ListBox_SizeChanged" VerticalAlignment="Stretch" SelectionMode="Extended" Style="{ StaticResource ListBoxWithAutoScroll_Horizontal }" &gt; &lt;ListBox.ItemsPanel&gt; &lt;ItemsPanelTemplate&gt; &lt;StackPanel Orientation="Horizontal"/&gt; &lt;/ItemsPanelTemplate&gt; &lt;/ListBox.ItemsPanel&gt; &lt;/ListBox&gt; &lt;StackPanel Grid.Row="2" HorizontalAlignment="Left" VerticalAlignment="Center" Orientation="Horizontal"&gt; &lt;Label Margin="5"&gt;View Scale:&lt;/Label&gt; &lt;Slider Name="sldView" Minimum="25" Maximum="100" IsSnapToTickEnabled="True" TickPlacement="BottomRight" Ticks="25,50,100" Width="125" ValueChanged="Slider_ValueChanged"/&gt; &lt;/StackPanel&gt; &lt;StackPanel Grid.Row="2" Orientation="Horizontal" VerticalAlignment="Top" HorizontalAlignment="Right" DockPanel.Dock="Right"&gt; &lt;Button Command="{Binding Path=StopCommand}" Content="Stop" Height="30" Width="60" Margin="1" IsEnabled="{Binding Path=CanStop}" x:Name="btnStop" /&gt; &lt;Button Command="{Binding Path=RunCommand}" Content="Run" Height="30" Width="60" IsEnabled="{Binding Path=CanRun}" x:Name="btnRun" HorizontalAlignment="Right" Margin="1"/&gt; &lt;/StackPanel&gt; </code></pre> <p>--Widget--</p> <pre><code> &lt;Grid&gt; &lt;Grid.RowDefinitions&gt; &lt;RowDefinition Height="Auto" /&gt; &lt;RowDefinition Height="*" /&gt; &lt;RowDefinition Height="*" /&gt; &lt;/Grid.RowDefinitions&gt; &lt;StackPanel Orientation="Horizontal" Grid.Row="0"&gt; &lt;StackPanel.ContextMenu&gt; &lt;ContextMenu&gt; &lt;MenuItem Header="Edit" Command="{Binding Path=EditCommand}" IsEnabled="{Binding IsMonitorStopped}"/&gt; &lt;MenuItem Header="Remove" Command="{Binding Path=RemoveCommand}" IsEnabled="{Binding IsMonitorStopped}"/&gt; &lt;/ContextMenu&gt; &lt;/StackPanel.ContextMenu&gt; &lt;Image Source="" Margin="2" /&gt; &lt;Label Content="{Binding Path=Name}" Margin="5,0,0,0" VerticalAlignment="Center"/&gt; &lt;/StackPanel&gt; &lt;ItemsControl Grid.Row="1" ItemsSource="{Binding Path=Entities}" Name="icEntities" &gt; &lt;ItemsControl.Resources&gt; &lt;DataTemplate DataType="{x:Type vm:AppleViewModel}"&gt; &lt;ct:AppleTile Height="{Binding Path=AppleHeight}" Width="{Binding Path=AppleWidth}" Grid.ColumnSpan="2" Grid.RowSpan="2"/&gt; &lt;/DataTemplate&gt; &lt;DataTemplate DataType="{x:Type vm:OrangeViewModel}"&gt; &lt;ct:OrangeTile Height="{Binding Path=OrangeHeight}" Width="{Binding Path=OrangeWidth}" Grid.ColumnSpan="2"/&gt; &lt;/DataTemplate&gt; &lt;DataTemplate DataType="{x:Type vm:GrapeViewModel}"&gt; &lt;ct:GrapeTile Height="{Binding Path=GrapeHeight}" Width="{Binding Path=GrapeWidth}" /&gt; &lt;/DataTemplate&gt; &lt;/ItemsControl.Resources&gt; &lt;ItemsControl.ItemsPanel&gt; &lt;ItemsPanelTemplate&gt; &lt;!-- Custom Wrap panel --&gt; &lt;co:MonitorPanel x:Name="mpMain"/&gt; &lt;/ItemsPanelTemplate&gt; &lt;/ItemsControl.ItemsPanel&gt; &lt;/ItemsControl&gt; &lt;/Grid&gt; </code></pre> <p>If the user moves the Slider bar for zoom in/zoom out - I need to be able to force the custom panels to re-render with the newly calculated widget sizes.</p> <pre><code>private void ListBox_SizeChanged(object sender, SizeChangedEventArgs e) { //Works perfect this.ResetViewScale(e.NewSize); } </code></pre> <p>...here comes trouble:</p> <pre><code> private void Slider_ValueChanged(object sender, RoutedPropertyChangedEventArgs&lt;double&gt; e) { ...code here this.ResetViewScale(new Size(this.myListBox.ActualWidth, this.myListBox.ActualHeight)); //How can I repaint my list/panel? } private void ResetViewScale(Size e) { Size newSize = new Size(e.Height / 2, e.Height / 2); switch (App.ApplicationViewScale) { case ViewScale.Full: Size full = new Size(newSize.Height, newSize.Height); App.TileSize = new Size(full.Height, full.Width); break; case ViewScale.Half: Size half = new Size(newSize.Height / 2, newSize.Height / 2); App.TileSize = new Size(half.Height, half.Width); break; case ViewScale.Quarter: Size quarter = new Size(newSize.Height / 4, newSize.Height / 4); App.TileSize = new Size(quarter.Height, quarter.Width); break; default: Size defaultToFull = new Size(newSize.Height, newSize.Height); App.TileSize = new Size(defaultToFull.Height, defaultToFull.Width); break; } } </code></pre> <p>I tried using all the Invalidate methods but nothing seems to be working. Sorta stuck...</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload