开发者

passing selectedItem as CommandParameter from DataGrid WPF

I have a Datagrid, which i have a Hyperlink column as 开发者_开发百科

When user clicks on this hyperlink i want to open a form on which i will be showing the salarybreakup for the selected Employee. Please let me know how can i pass the EmployeeId of the selected record as command parameter, so that i can show ite detail.


I don't know exactly how to do it with DataGrid because I don't use it, But in ListBox you can apply data template like this (everything irrelevant removed):

<DataTemplate>
    <Grid>
        <Hyperlink Command="{Binding DataContext.MyCommand, 
                             RelativeSource={RelativeSource AncestorType={x:Type ListBox}, 
                             Mode=FindAncestor}}"
                   CommandParameter="{Binding}"/>
    </Grid>
</DataTemplate>

Here I suppose that you have MyCommand property for your command in ListBox's DataContext.

Also sorry for offtop, but are your users really need exactly DataGrid with its all-in-one-row silly excel-like design? This is the worst way to display any data. Maybe it's better to use well-styled ListBox? Often developers use DataGrid because its easy do display a content of some table from database. But easy to display and easy to use are not the same things. So, if you don't need any extra functionality of DataGrid, use other controls.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜