Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save myd7349/5ed0757479f2fdd24e913e32c3f5d84a to your computer and use it in GitHub Desktop.
Save myd7349/5ed0757479f2fdd24e913e32c3f5d84a to your computer and use it in GitHub Desktop.
ItemsControl with ScrollViewer inside Template
<Page
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:dd="urn:gong-wpf-dragdrop">
<Grid>
<ItemsControl x:Name="pnlBilder"
HorizontalAlignment="Center"
Width="300" Height="100"
dd:DragDrop.IsDragSource="True"
ScrollViewer.HorizontalScrollBarVisibility="Disabled"
ScrollViewer.VerticalScrollBarVisibility="Auto"
dd:DragDrop.IsDropTarget="True"
dd:DragDrop.DropScrollingMode="Both" >
<ItemsControl.ItemTemplate>
<DataTemplate>
<local:CoolView x:Name="ctrlView" Width="100" Height="100" />
</DataTemplate>
</ItemsControl.ItemTemplate>
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.Template>
<ControlTemplate TargetType="{x:Type ItemsControl}">
<Border x:Name="Border"
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}">
<ScrollViewer Margin="0"
Focusable="False"
Padding="{TemplateBinding Padding}"
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
HorizontalScrollBarVisibility="{TemplateBinding ScrollViewer.HorizontalScrollBarVisibility}"
VerticalScrollBarVisibility="{TemplateBinding ScrollViewer.VerticalScrollBarVisibility}"
CanContentScroll="{TemplateBinding ScrollViewer.CanContentScroll}">
<ItemsPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
</ScrollViewer>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsEnabled" Value="False">
<Setter TargetName="Border" Property="Background" Value="Gray" />
<Setter TargetName="Border" Property="BorderBrush" Value="Silver" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</ItemsControl.Template>
</ItemsControl>
</Grid>
</Page>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment