I done that registering a Javascript event and manually calling back my server controls. Some important pieces below:
<asp:Silverlight runat="server" ID="SilverlightUpload"
Source="~/ClientBin/Silverlight.xap" OnPluginLoaded="pluginLoaded" />
<asp:Button runat="server" OnClientClick="return cancelUpload()" Text="Cancel" />
<script type="text/javascript">
var uploadControl = null;
function pluginLoaded(sender) {
uploadControl = sender.get_element().content.uploadControl;
uploadControl.addEventListener("OnFileListChanged", onFileListChanged);
}
function onFileListChanged(sender, e) {
var files = [];
for (var i = 0; i < e.Files.length; i++) {
files[i] = {
Id : e.Files[i].Id,
Name : e.Files[i].Name
};
}
__doPostBack("<%= RadGrid1.UniqueID %>",
"OnFileListChanged:" + JSON.stringify(files));
}
function cancelUpload() {
$find("<%= SilverlightUpload.ClientID %>")
.get_element().content.uploadControl.StopUpload();
return false;
}
</script>
And Silverlight codebehind:
[ScriptableType] // MUST
public partial class Page : UserControl
{
[ScriptableMember] // MUST
public event EventHandler<FileListChangedEventArgs> OnFileListChanged;
[ScriptableMember] // MUST
public void StopUpload() { }
}
[ScriptableType]
public class FileListChangedEventArgs : EventArgs
{
public FileUploadItem[] Files { get; internal set; }
}
[DataContract]
[ScriptableType]
public class FileUploadItem
{
}