如何在MVVM WPF中的Telerik RadDataForm中使用FileUpload?

时间:2015-06-18 14:26:54

标签: c# wpf mvvm caliburn.micro

我正在使用WPFMVVM模式开发caliburn.micro应用程序。当我需要使用fileuploadopenfiledialog使用计算机的本地路径时,我会陷入困境。我需要在数据库中插入路径。这是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>

我在ICollectionView中使用datasource作为viewmodel。也许我需要在datatemplate中使用dataform,但我不知道该怎么做。如果您需要任何其他信息,请与我们联系。

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 个答案:

没有答案