devexpress套餐中UploadControl实现自定义参数传递的例子

 

 public partial class MainPage : UserControl {
        public MainPage() {
            InitializeComponent();
            uploadControl.UserID = 1112;
        }
    }
    public class CustomUploadControl : UploadControl {
        public int UserID {
            get { return ((CustomUploader)Uploader).UserID; }
            set { ((CustomUploader)Uploader).UserID = value; }
        }

        protected override Uploader CreateUploader() {
            return new CustomUploader(Dispatcher);
        }
    }
    class CustomUploader : Uploader {
        public CustomUploader(Dispatcher dispatcher) : base(dispatcher) { }

        public int UserID {
            get { return ((CustomUploadService)UploadService).UserID; }
            set { ((CustomUploadService)UploadService).UserID = value; }
        }

        protected override IUploadService CreateUploadService() {
            return new CustomUploadService(Dispatcher);
        }
    }
    class CustomUploadService : HttpWebRequestUploadService {
        public CustomUploadService(Dispatcher dispatcher) : base(dispatcher) { }

        public int UserID { get; set; }

        protected override Uri PrepareAddress() {
            string uri = string.Format("{0}&userID={1}", base.PrepareAddress().AbsoluteUri, UserID);
            return new Uri(uri, UriKind.Absolute);
        }
    }

 

 

页面如下:

 <Grid x:Name="LayoutRoot" Background="White">
        <local:CustomUploadControl
            x:Name="uploadControl" Width="532" Background="White"
            MaxFileSize="1000000" MaxUploadSize="3000000" MaxFileCount="5"
            FileNameFilter="Image files (*.jpg;*.jpeg;*.png;*.bmp;*.tif;*.tiff;*.gif)|*.jpg;*.jpeg;*.png;*.bmp;*.tif;*.tiff;*.gif"
            WebHandlerUri="http://localhost:1000/UploadHandler.ashx" UploadServerPath="Data"/>
    </Grid>

posted @ 2011-10-28 15:22  greystar  阅读(541)  评论(0编辑  收藏  举报