Skip to content

Instantly share code, notes, and snippets.

@henninga
Created October 31, 2011 15:05
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 henninga/1327688 to your computer and use it in GitHub Desktop.
Save henninga/1327688 to your computer and use it in GitHub Desktop.
User control for each item in listbox
<UserControl x:Class="AssetTracker.Views.VersionView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:AssetTracker.UserControls" xmlns:cm="clr-namespace:Caliburn.Micro;assembly=Caliburn.Micro" xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity" xmlns:Triggers="clr-namespace:AssetTracker.Triggers">
<DockPanel LastChildFill="True">
<local:HyperlinkButton DockPanel.Dock="Top" x:Name="NewLicense" HorizontalAlignment="Right" >
<TextBlock Text="+ Ny lisens" />
</local:HyperlinkButton>
<ListBox x:Name="Licenses"
DockPanel.Dock="Bottom"
Style="{StaticResource licenses}"
ScrollViewer.CanContentScroll="True"
VerticalContentAlignment="Center"
HorizontalContentAlignment="Stretch">
<ListBox.ItemTemplate >
<DataTemplate >
<Border Background="Transparent"> <!--Background is set to Transparent so the context menu will appear on the entire item and not where controls are painted/displayed.-->
<ContentControl cm:View.Model="{Binding}" VerticalContentAlignment="Stretch" HorizontalContentAlignment="Stretch" IsTabStop="False" />
<ContextMenuService.ContextMenu>
<ContextMenu >
<MenuItem Header="Copy to clipboard" cm:Message.Attach="[Event Click] = [Action CopyKey()]" />
</ContextMenu>
</ContextMenuService.ContextMenu>
</Border>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</DockPanel>
</UserControl>
<UserControl x:Class="AssetTracker.Views.IndividualLicenseView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity" xmlns:local="clr-namespace:AssetTracker.Triggers" xmlns:cl="clr-namespace:Caliburn.Micro;assembly=Caliburn.Micro">
<DockPanel LastChildFill="False" >
<StackPanel Orientation="Vertical" DockPanel.Dock="Left">
<TextBlock x:Name="Key" FontSize="18" >
</TextBlock>
<TextBlock x:Name="Username" FontSize="14" Foreground="Gray" />
</StackPanel>
<StackPanel DockPanel.Dock="Right" Orientation="Horizontal">
<Button x:Name="AssignUser" Content="Tildel" />
<Button x:Name="EditLicense" Content="Endre" />
<Button x:Name="DeleteLicense" Content="Slett" />
<i:Interaction.Triggers>
<local:InputBindingTrigger >
<local:InputBindingTrigger.InputBinding >
<KeyBinding Modifiers="Ctrl" Key="C"/>
</local:InputBindingTrigger.InputBinding>
<cl:ActionMessage MethodName="CopyKey" />
</local:InputBindingTrigger>
</i:Interaction.Triggers>
</StackPanel>
</DockPanel>
</UserControl>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment