ListBox經過MVVM實現雙擊

一、實現的效果,當我雙擊左邊帳戶列表時,可以查到對應的帳戶數據:express

二、xaml實現:code

<ListBox Grid.Column="0" 
         ItemsSource="{Binding AcctBillList}"
         SelectedItem="{Binding AcctBillSelectItem}">
    <i:Interaction.Triggers>
        <i:EventTrigger EventName="MouseDoubleClick">
            <i:InvokeCommandAction Command="{Binding AcctBillChkCmd}" />
        </i:EventTrigger>
    </i:Interaction.Triggers>
    <ListBox.ItemTemplate>
        <DataTemplate>
            <Grid Height="Auto" Margin="0,0,0,0">
                <TextBlock Text="{Binding FundAccount}"/>
            </Grid>
        </DataTemplate>
    </ListBox.ItemTemplate>
</ListBox>

說明:xml

    1)、ListBox顯示Item須要經過DataTemplate和TextBlockblog

    2)、ListBox沒有對應的雙擊命令,所以須要將事件轉爲命令,須要經過Trigger,並使用MouseDoubleClick事件。事件

    3)、使用Trigger須要引入:it

    xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"io

    xmlns:ei="http://schemas.microsoft.com/expression/2010/interactions"List

    Microsoft.Expression.Interactions.dllim

    System.Windows.Interactivity.dll數據

相關文章
相關標籤/搜索