Note that there are some explanatory texts on larger screens.

plurals
  1. POVertical WrapPanel inside expander; I'm not able to wrap at window bottom
    primarykey
    data
    text
    <p>I'm working on a WPF project build a couple of years ago. </p> <p>One control is an expander control which groups a list of check-controls. </p> <p>This list of check-controls is arranged from Left to Right, Top to Bottom by a WrapPanel!</p> <p><strong>Now my goal is to arrange the check-controls from Top to Bottom, Left to Right where the vertical wrap occurs at the bottom of the parent window! Any tips/directions in how to achieve this would be awsome!!</strong></p> <p>I have extracted the issue in a code example to highlight the issue. </p> <p><strong>Behavior of the example:</strong> The code example has the WrapPanel's orientation set to Horizontal. This is to show you what sort of behavior I would like to achieve! The wrap breaks at the Right side of the parent window and a new row starts. When the check-controls overflow the Bottom of the screen a vertical scrollbar appears.</p> <p><strong>Behavior I would like to achieve:</strong> When the Bottom side of the parent window is reached (when the wrappanel is set to Vertical orientation) I want the wrap to break and start at the Top again. When the check-controls overflow the Right side of the window I want a horizontal scrollbar to appear.</p> <p><strong>Example:</strong> In the code: change the Orientation attribute of the Wrappanel to Vertical. Notice that there is only one column overflowing all the way down, there is no wrap at the bottom of the window! Because I'm not sure how to attach a zip file (with the demo project) I have added the code files below. Creating a WPF application (.net framework 3.5) and copying the code in the proper locations should do. If you do have issues running the example I can always mail you a VS2010 solution! </p> <p>Project called VerticalWrapPanel</p> <p><strong>UserControl CheckControl.xaml</strong></p> <pre><code>&lt;UserControl x:Class="VerticalWrapPanel.CheckControl" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"&gt; &lt;Border BorderThickness="1,1,1,1" BorderBrush="Black"&gt; &lt;Label Content="{Binding Label}"/&gt; &lt;/Border&gt; &lt;/UserControl&gt; </code></pre> <p><strong>UserControl CheckGroupControl.xaml</strong></p> <pre><code>&lt;UserControl x:Class="VerticalWrapPanel.CheckGroupControl" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:controls="clr-namespace:VerticalWrapPanel" x:Name="GroupControl"&gt; &lt;UserControl.Resources&gt; &lt;DataTemplate x:Key="CheckTemplate"&gt; &lt;controls:CheckControl /&gt; &lt;/DataTemplate&gt; &lt;/UserControl.Resources&gt; &lt;Expander BorderBrush="Black" Header="TEST" IsExpanded="{Binding ElementName=GroupControl, Path=IsExpanded}"&gt; &lt;ItemsControl ItemsSource="{Binding Checks}" ItemTemplate="{StaticResource CheckTemplate}"&gt; &lt;ItemsControl.ItemsPanel&gt; &lt;ItemsPanelTemplate&gt; &lt;WrapPanel Orientation="Horizontal" /&gt; &lt;/ItemsPanelTemplate&gt; &lt;/ItemsControl.ItemsPanel&gt; &lt;/ItemsControl&gt; &lt;/Expander&gt; &lt;/UserControl&gt; </code></pre> <p><strong>CheckGroupControl.xaml.cs</strong></p> <pre><code>using System.Windows; using System.Windows.Controls; namespace VerticalWrapPanel { /// &lt;summary&gt; /// Interaction logic for CheckGroupControl.xaml /// &lt;/summary&gt; public partial class CheckGroupControl : UserControl { public CheckGroupControl() { InitializeComponent(); } public static DependencyProperty IsExpandedProperty = DependencyProperty.Register("IsExpanded", typeof(bool), typeof(CheckGroupControl)); public bool IsExpanded { get { return (bool)GetValue(IsExpandedProperty); } set { SetValue(IsExpandedProperty, value); } } } } </code></pre> <p><strong>MainWindow.xaml</strong></p> <pre><code>&lt;Window x:Class="VerticalWrapPanel.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:controls="clr-namespace:VerticalWrapPanel" Title="MainWindow" Height="350" Width="525" Loaded="Window_Loaded"&gt; &lt;Window.Resources&gt; &lt;DataTemplate x:Key="CheckGroupsTemplate"&gt; &lt;controls:CheckGroupControl /&gt; &lt;/DataTemplate&gt; &lt;/Window.Resources&gt; &lt;ScrollViewer CanContentScroll="False"&gt; &lt;ItemsControl ItemsSource="{Binding CheckGroups}" ItemTemplate="{StaticResource CheckGroupsTemplate}" /&gt; &lt;/ScrollViewer&gt; &lt;/Window&gt; </code></pre> <p><strong>MainWindow.xaml.cs</strong></p> <pre><code>using System.Collections.Generic; using System.Collections.ObjectModel; using System.Windows; namespace VerticalWrapPanel { public class MyModel { public ObservableCollection&lt;CheckGroup&gt; CheckGroups { get; set; } } public class Check { public string Label { get; set; } } public class CheckGroup { public List&lt;Check&gt; Checks { get; set; } } public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); } private void Window_Loaded(object sender, RoutedEventArgs e) { DataContext = new MyModel { CheckGroups = new ObservableCollection&lt;CheckGroup&gt; { new CheckGroup { Checks = new List&lt;Check&gt; { new Check {Label = "Check 0001"} ,new Check {Label = "Check 0002"} ,new Check {Label = "Check 0003"} ,new Check {Label = "Check 0004"} ,new Check {Label = "Check 0005"} ,new Check {Label = "Check 0006"} ,new Check {Label = "Check 0007"} ,new Check {Label = "Check 0008"} ,new Check {Label = "Check 0009"} ,new Check {Label = "Check 0000"} ,new Check {Label = "Check 0002"} ,new Check {Label = "Check 0003"} ,new Check {Label = "Check 0004"} ,new Check {Label = "Check 0005"} ,new Check {Label = "Check 0006"} ,new Check {Label = "Check 0007"} ,new Check {Label = "Check 0008"} ,new Check {Label = "Check 0009"} ,new Check {Label = "Check 0000"} ,new Check {Label = "Check 0002"} ,new Check {Label = "Check 0003"} ,new Check {Label = "Check 0004"} ,new Check {Label = "Check 0005"} ,new Check {Label = "Check 0006"} ,new Check {Label = "Check 0007"} ,new Check {Label = "Check 0008"} ,new Check {Label = "Check 0009"} ,new Check {Label = "Check 0000"} } } , new CheckGroup { Checks = new List&lt;Check&gt; { new Check {Label = "Check 0011"} ,new Check {Label = "Check 0012"} ,new Check {Label = "Check 0013"} ,new Check {Label = "Check 0014"} ,new Check {Label = "Check 0015"} ,new Check {Label = "Check 0016"} ,new Check {Label = "Check 0017"} ,new Check {Label = "Check 0018"} ,new Check {Label = "Check 0019"} ,new Check {Label = "Check 0010"} } } } }; } } } </code></pre>
    singulars
    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