Wpf为listview中的项添加单击功能

时间:2016-08-15 17:47:58

标签: wpf listview onclicklistener

的Xaml:

<Window x:Class="Berichtensysteem.Window1"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
            xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
            xmlns:local="clr-namespace:Berichtensysteem"
            mc:Ignorable="d"
            Title="Mailclient" Height="800" Width="800"
            >

        <Grid>

            <UserControl>
                <Grid Margin="0,-10,177,10">
                    <Button x:Name="inboxClick" Content="Inbox" HorizontalAlignment="Left" VerticalAlignment="Top" Width="121" Margin="1,56,0,0"/>
                    <Button x:Name="outbox" Content="Verzonden berichten" HorizontalAlignment="Left" VerticalAlignment="Top" Width="120" Margin="1,96,0,0"/>
                    <Button x:Name="deleted" Content="Verwijderde berichten" HorizontalAlignment="Left" VerticalAlignment="Top" Width="121" Margin="1,76,0,0"/>

                </Grid>
            </UserControl>


            <ListView Margin="126,45,0,0" Name="inbox">
                <ListView.View>
                    <GridView>
                        <GridViewColumn Header="From" Width="70" DisplayMemberBinding="{Binding from}" />
                        <GridViewColumn Header="Subject" Width="120" DisplayMemberBinding="{Binding subject}" />
                        <GridViewColumn Header="Content" Width="150" DisplayMemberBinding="{Binding content}" />
                    </GridView>
                </ListView.View>
            </ListView>
        </Grid>
    </Window>

代码背后:

    public partial class Window1 : Window
    {
        private static databaselinkDataContext _dataDC = new databaselinkDataContext();
        public Window1(String username)
        {
            InitializeComponent();
            sendMail();



            List<email> _mails = _dataDC.emails.ToList();
            inbox.ItemsSource = _mails;

        }

// Adding an email to the database because I haven't set up send mails yet.

        public void sendMail()
        {
            var _email = new email();
            _email.content = "Mijn inhoud";
            _email.from = "hallo";
            _email.subject = "myemailsubject";
            _email.layout = "";

            _dataDC.emails.InsertOnSubmit(_email);
            _dataDC.SubmitChanges();
        }
    }
}

因此。我有我的邮件,我已设法在列表视图中显示它们。我想在点击后显示电子邮件的完整内容。要做到这一点,我需要做的事情:

  1. 为每个listview项添加一个点击监听器(类似于android中的recyclerview?)。
  2. 将listview替换为电子邮件的内容,同时保持我的usecontrol。
  3. 有任何简单的方法吗?

0 个答案:

没有答案