Click here to Skip to main content
15,922,145 members
Home / Discussions / WPF
   

WPF

 
AnswerRe: Small question re: customized controls in WPF Pin
Pete O'Hanlon5-Sep-08 10:07
mvePete O'Hanlon5-Sep-08 10:07 
GeneralRe: Small question re: customized controls in WPF Pin
chaiguy13375-Sep-08 10:11
chaiguy13375-Sep-08 10:11 
GeneralRe: Small question re: customized controls in WPF Pin
Insincere Dave5-Sep-08 12:49
Insincere Dave5-Sep-08 12:49 
GeneralRe: Small question re: customized controls in WPF Pin
chaiguy13375-Sep-08 20:06
chaiguy13375-Sep-08 20:06 
GeneralRe: Small question re: customized controls in WPF Pin
Pete O'Hanlon5-Sep-08 22:55
mvePete O'Hanlon5-Sep-08 22:55 
QuestionWPF - Creating Controls Dynamically on a Stack Panel Pin
Jonso4-Sep-08 15:15
Jonso4-Sep-08 15:15 
QuestionHow to enable Context menu for a listbox item. Pin
Aslesh4-Sep-08 6:22
Aslesh4-Sep-08 6:22 
AnswerRe: How to enable Context menu for a listbox item. Pin
Pete O'Hanlon4-Sep-08 8:42
mvePete O'Hanlon4-Sep-08 8:42 
Santhapur, try this:
<Window x:Class="HDI_WPF_ListItemTemplate_cs.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Window1" Height="300" Width="300" Loaded="Window_Loaded">
  <Window.Resources>
    <ContextMenu x:Key="myMenu">
      <MenuItem Header="my text" />
    </ContextMenu>
  </Window.Resources>
  <Grid>
    <ListBox x:Name="lstItems" Width="300" MaxHeight="300" FontSize="16">
      <ListBox.ItemTemplate>
        <DataTemplate>
          <Border BorderBrush="Blue" Margin="0,4,0,4" BorderThickness="1" CornerRadius="5">
            <StackPanel Orientation="Vertical" ContextMenu="{StaticResource myMenu}">
              <StackPanel Orientation="Horizontal" Background="AntiqueWhite">
                <TextBlock FontSize="16" Text="{Binding Path=FirstName}" />
                <TextBlock FontSize="16" Text=" " />
                <TextBlock FontSize="16" Text="{Binding Path=LastName}" />
              </StackPanel>
              <TextBlock FontSize="12" Text="{Binding Path=Age}" />
              <TextBlock FontSize="12" Text="{Binding Path=FavoriteMovie}" />
            </StackPanel>
          </Border>
        </DataTemplate>
      </ListBox.ItemTemplate>
      <ListBox.ItemsPanel>
        <ItemsPanelTemplate>
          <StackPanel Orientation="Vertical" />
        </ItemsPanelTemplate>
      </ListBox.ItemsPanel>
    </ListBox>
  </Grid>
</Window>
Here I've added the context menu as a resource, and referred to it from the StackPanel. By doing this, the context menu will only appear when you click on the item itself rather than space at the side.

Deja View - the feeling that you've seen this post before.

My blog | My articles



Questionparsing HTML files Pin
swatikavdia3-Sep-08 23:33
swatikavdia3-Sep-08 23:33 
AnswerRe: parsing HTML files Pin
Michael Sync18-Oct-08 22:02
Michael Sync18-Oct-08 22:02 
QuestionAudio conferencing using WCF and WPF Pin
sumantamca3-Sep-08 21:55
sumantamca3-Sep-08 21:55 
QuestionParsing XML files [modified] Pin
skrajasthan3-Sep-08 21:52
skrajasthan3-Sep-08 21:52 
GeneralRe: Parsing XML files Pin
Pete O'Hanlon14-Sep-08 22:54
mvePete O'Hanlon14-Sep-08 22:54 
Questionreading XML files Pin
swatikavdia3-Sep-08 21:08
swatikavdia3-Sep-08 21:08 
AnswerRe: reading XML files Pin
Michael Sync18-Oct-08 22:08
Michael Sync18-Oct-08 22:08 
QuestionTextbox validation Pin
Aslesh3-Sep-08 4:52
Aslesh3-Sep-08 4:52 
AnswerRe: Textbox validation Pin
Pete O'Hanlon3-Sep-08 10:21
mvePete O'Hanlon3-Sep-08 10:21 
QuestionHow to animate Expander ? Pin
hdv2123-Sep-08 1:17
hdv2123-Sep-08 1:17 
AnswerRe: How to animate Expander ? Pin
Pete O'Hanlon3-Sep-08 1:25
mvePete O'Hanlon3-Sep-08 1:25 
QuestionAbout eml file parsing in silverlight Pin
skrajasthan2-Sep-08 23:58
skrajasthan2-Sep-08 23:58 
QuestionAdvantages of Silver light for user using silver light application ? Pin
King Shez2-Sep-08 21:47
King Shez2-Sep-08 21:47 
QuestionHelp: Audio conferencing using WCF Pin
Jasvinder Kumar Bali2-Sep-08 20:53
Jasvinder Kumar Bali2-Sep-08 20:53 
QuestionSaving a image of WPF form Pin
shazaduh2-Sep-08 10:03
shazaduh2-Sep-08 10:03 
AnswerRe: Saving a image of WPF form Pin
Mark Salsbery2-Sep-08 10:48
Mark Salsbery2-Sep-08 10:48 
QuestionHow to add the custom control in tool box using wpf Pin
bruze2-Sep-08 5:23
bruze2-Sep-08 5:23 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.