Skip to content

Instantly share code, notes, and snippets.

@sakapon
Last active August 29, 2015 14:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sakapon/88eb8440a779be13e896 to your computer and use it in GitHub Desktop.
Save sakapon/88eb8440a779be13e896 to your computer and use it in GitHub Desktop.
WpfSample / LayoutWpf
using System;
using System.Collections.Generic;
using System.Linq;
namespace LayoutWpf
{
public class AppModel
{
public int[] Numbers { get; private set; }
public AppModel()
{
Numbers = Enumerable.Range(1, 15).ToArray();
}
}
}
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:LayoutWpf" x:Class="LayoutWpf.MainWindow"
Title="MainWindow" Width="900" Height="600" FontSize="32">
<Window.Resources>
<ItemsPanelTemplate x:Key="NumbersPanelTemplate">
<WrapPanel IsItemsHost="True"/>
</ItemsPanelTemplate>
<DataTemplate x:Key="NumberDataTemplate">
<TextBlock Text="{Binding Mode=OneWay, StringFormat=No.\{0\}}" Width="120" TextAlignment="Center"/>
</DataTemplate>
</Window.Resources>
<Window.DataContext>
<local:AppModel/>
</Window.DataContext>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<Grid Margin="20" Background="#FFEECCBB">
<ItemsControl ItemsSource="{Binding Numbers}" ItemsPanel="{DynamicResource NumbersPanelTemplate}" ItemTemplate="{DynamicResource NumberDataTemplate}"/>
</Grid>
<ScrollViewer Grid.Column="1" Margin="20" Background="#FFCCEEBB">
<ItemsControl ItemsSource="{Binding Numbers}" ItemsPanel="{DynamicResource NumbersPanelTemplate}" ItemTemplate="{DynamicResource NumberDataTemplate}"/>
</ScrollViewer>
<Viewbox Grid.Row="1" Margin="20">
<Grid Width="390" Height="260" Background="#FFBBCCEE">
<ItemsControl ItemsSource="{Binding Numbers}" ItemsPanel="{DynamicResource NumbersPanelTemplate}" ItemTemplate="{DynamicResource NumberDataTemplate}"/>
</Grid>
</Viewbox>
<Grid Grid.Row="1" Grid.Column="1" Margin="20" Background="#FFFFEEBB">
<Viewbox MaxWidth="360" HorizontalAlignment="Left" VerticalAlignment="Top">
<Grid Width="360" Background="LightGray">
<ItemsControl ItemsSource="{Binding Numbers}" ItemsPanel="{DynamicResource NumbersPanelTemplate}" ItemTemplate="{DynamicResource NumberDataTemplate}"/>
</Grid>
</Viewbox>
</Grid>
</Grid>
</Window>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment