Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. WPF
  4. ListBox With Hyperlinks - Pass Bound Item

ListBox With Hyperlinks - Pass Bound Item

Scheduled Pinned Locked Moved WPF
helpwpfwcfquestion
1 Posts 1 Posters 3 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    Kevin Marois
    wrote on last edited by
    #1

    I have this listbox that displays its items as hyperlinks. The problem is that the click event is passing the hyperlink as the event args, not the bound NavigationEntity. What's the right way to do this?

    <ListBox x:Name="listBox1"
    ItemsSource="{Binding Items, RelativeSource={RelativeSource TemplatedParent}}"
    ScrollViewer.HorizontalScrollBarVisibility="Auto"
    ScrollViewer.VerticalScrollBarVisibility="Auto"
    Margin="2"
    BorderBrush="Transparent"
    BorderThickness="0">

    <ListBox.ItemTemplate>
        <DataTemplate>
    
            <TextBlock>
    
            <Hyperlink Foreground="SteelBlue"
                        TextDecorations="Underline">
    
                <TextBlock Text="{Binding Caption}"/>
                                
                <i:Interaction.Triggers>
                    <i:EventTrigger EventName="Click">
                        <i:InvokeCommandAction Command="{Binding RelativeSource={RelativeSource FindAncestor, 
                                                    AncestorType={x:Type ctrls:NavigationPane}}, Path=ItemClickedCommand}"
                                                PassEventArgsToCommand="True"/>
                    </i:EventTrigger>
                </i:Interaction.Triggers>
                                
            </Hyperlink>
    
        </TextBlock>
    
        </DataTemplate>
    </ListBox.ItemTemplate>
    

    </ListBox>

    The listbox is bound to a collection of NavigationEntity

    public class NavigationEntity : _EntityBase
    {
    public int Id { get; set; }

    private string? \_Caption;
    public string Caption
    {
        get { return \_Caption; }
        set
        {
            if (\_Caption != value)
            {
                \_Caption = value;
                RaisePropertyChanged(nameof(Caption));
            }
        }
    }
    
    private NavigationItemType \_ItemType;
    public NavigationItemType ItemType
    {
        get { return \_ItemType; }
        set
        {
            if (\_ItemType != value)
            {
                \_ItemType = value;
                RaisePropertyChanged(nameof(ItemType));
            }
        }
    }
    

    }

    If it's not broken, fix it until it is. Everything makes sense in someone's mind. Ya can't fix stupid.

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups