开发者

Silverlight 3 button click argument

开发者 https://www.devze.com 2022-12-19 00:52 出处:网络
I\'m just beginning with Silverlight. I have a DataGrid whose ItemsSource is linked to an ObservableCollection. Each row of the DataGrid (AutoGenerateColumns= \"False\") has some values from an object

I'm just beginning with Silverlight. I have a DataGrid whose ItemsSource is linked to an ObservableCollection. Each row of the DataGrid (AutoGenerateColumns= "False") has some values from an object and a button. How can I associate a "command argument" to the button so that I know what button of what row is being clicked?

Thanks开发者_如何学Python


You can use Tag attrribute for that. Assuming that the objects in the collection have "Id" property you can bind the "Tag" attribute of the button control to the Id of the object with:

<Button Tag="{Binding Id}" .../>

or you can store the entire object in Tag

<Button Tag="{Binding Path=.}" .../>

Then in click handler you have to use the sender parameter to get the sender control and extract the tag info:

Button btn = sender as Button;
var tagValue = btn.Tag; // object binded to "tag" attribute


I've found about the DataContext property of the Button objects that, in this case, returns the object on which the row is based.

0

精彩评论

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

关注公众号