How to use FileUpload in Telerik RadDataForm in MVVM WPF?

180 views Asked by At

I am developing a WPF application in MVVM pattern using caliburn.micro. I am stuck when I need to use a local path of my computer using fileupload or openfiledialog. I need to insert the path in the database. Here is the xaml:

<Grid Margin="20" Height="Auto" Width="Auto">
    <Grid.RowDefinitions>
        <RowDefinition Height="50*"></RowDefinition>
        <RowDefinition Height="50*"></RowDefinition>
    </Grid.RowDefinitions>
    <Telerik:RadGridView x:Name="RadGridView1" GroupRenderMode="Flat"
                         ItemsSource="{Binding ModelList}"
                         ColumnWidth="*"
                         CanUserFreezeColumns="False"
                         RowIndicatorVisibility="Collapsed">
    </Telerik:RadGridView>
    <Telerik:RadDataForm Grid.Row="1" 
                         x:Name="myRadDataForm"
                         ItemsSource="{Binding ModelList}"
                         Header="Model Details"
                         Margin="0,5,0,0" cal:Message.Attach="[Event DeletingItem] = [Action onDeleted()]">
    </Telerik:RadDataForm>
</Grid>

I am using an ICollectionView as a datasource in viewmodel. Maybe I need to use a datatemplate in the dataform, but I don't know how to do that. Please let me know if you need any other info.

Code for ViewModel:

[Export(typeof(AddModelsViewModel))]
public class AddModelsViewModel : PropertyChangedBase
{
    private Model _selectmodel;
    List<Model> ModelsList = new List<Model>();
    Model model = new Model();
    private ICollectionView models = null;
    public ICollectionView Models
    {
        get
        {
            if (this.models == null)
            {
                ObservableCollection<Model> allModels = new ObservableCollection<Model>();
                ModelsList = model.GetAllModels();
                foreach (Model m in ModelsList)
                {
                    allModels.Add(m);
                }
                this.models = new QueryableCollectionView(allModels);
            }
            return this.models;
        }
    }

    //  Model model = new Model();
    private List<Model> _ModelListAll;
    // private ClsRole _selectedRole;

    public Model selectedModel
    {
        get { return _selectmodel; }
        set
        {
            _selectmodel = value;
            NotifyOfPropertyChange(() => selectedModel);
        }
    }
    public List<Model> ModelListAll
    {
        get { return _ModelListAll; }
        set
        {
            _ModelListAll = value;
            NotifyOfPropertyChange(() => ModelListAll);
        }
    }
    public void onDeleted()
    {
        try
        {
            model.Delete(selectedModel);
        }
        catch (Exception ex)
        {
            Logger.GetInstance().Log(ex);
        }
    }
    public void OnRoleViewLoad()
    {
        ModelListAll = model.GetAllModels();
        if (ModelListAll.Count > 0)
        {
            selectedModel = ModelListAll[0];
        }
    }
    private ICollectionView modelList = null;
    public ICollectionView ModelList
    {
        get
        {
            if (this.modelList == null)
            {
                ObservableCollection<Model> Allmodel = new ObservableCollection<Model>();

                ModelListAll = model.GetAllModels();

                foreach (Model role in ModelListAll)
                {
                    Allmodel.Add(role);
                }
                this.modelList = new QueryableCollectionView(Allmodel);
            }
            return this.modelList;
        }

        set
        {
            ModelList = value;
            NotifyOfPropertyChange(() => ModelList);
        }
    }

    public void OnRadGridView1SelectonChanged(Model modelClicked)
    {
        selectedModel = modelClicked;
    }

}
0

There are 0 answers