Skip to content

Instantly share code, notes, and snippets.

@julesx
Created April 21, 2015 15:35
Show Gist options
  • Save julesx/cbb49065c80bd19e420a to your computer and use it in GitHub Desktop.
Save julesx/cbb49065c80bd19e420a to your computer and use it in GitHub Desktop.
button with context menu
<Button Name="MainOptionsButton">
<i:Interaction.Triggers>
<i:EventTrigger EventName="Click">
<ei:ChangePropertyAction TargetObject="{Binding ContextMenu, ElementName=MainOptionsButton}" PropertyName="PlacementTarget" Value="{Binding ElementName=MainOptionsButton, Mode=OneWay}"/>
<ei:ChangePropertyAction TargetObject="{Binding ContextMenu, ElementName=MainOptionsButton}" PropertyName="IsOpen" Value="True"/>
</i:EventTrigger>
</i:Interaction.Triggers>
<Button.Resources>
<CollectionViewSource Source="{Binding LoggedInServers}" x:Key="LoggedInServers" />
</Button.Resources>
<Button.ContextMenu>
<ContextMenu Placement="Top">
<MenuItem Header="Sign out from">
<MenuItem.ItemsSource>
<CompositeCollection>
<CollectionContainer Collection="{Binding Source={StaticResource LoggedInServers}}" />
<Separator />
<MenuItem Command="{Binding CmdLogout}" Header="All Servers" />
</CompositeCollection>
</MenuItem.ItemsSource>
</MenuItem>
</ContextMenu>
</Button.ContextMenu>
<Rectangle Width="15" Height="15">
<Rectangle.Fill>
<VisualBrush Stretch="Fill" Visual="{StaticResource appbar_settings}" />
</Rectangle.Fill>
</Rectangle>
</Button>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment