WPF + DevExpress学习07

Prism 子界面和父界面相互传值

1 首先需要创建一个子界面 名称 AddTaskDialog 和 ViewModels

<UserControl x:Class="GanttProject.Views.AddTaskDialog"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:prism="http://prismlibrary.com/" xmlns:dxg="http://schemas.devexpress.com/winfx/2008/xaml/grid"
             prism:ViewModelLocator.AutoWireViewModel="True"
              Width="401" MinWidth="401" MaxWidth="401"
             Padding="10"
             >
    <Grid>
    Grid>
UserControl>
AddTaskDialogViewModel 继承 IDialogAware
public class AddTaskDialogViewModel : BindableBase,IDialogAware{
    public string Title => "添加任务";
public event Action<IDialogResult> RequestClose;
  public bool CanCloseDialog()
        {
            return true;
        }

        public void OnDialogClosed()
        {
            MessageBox.Show("窗口关闭了!");
        }
          public DelegateCommand BtnCloseCommand
         {
            get => new DelegateCommand(() =>
            {
                DialogParameters dialogParameters = new DialogParameters();
          		 // 向父级页面 传参数 dialogParameters  key value 形式的
                 // 关闭当前窗口
                 RequestClose?.Invoke(new DialogResult(ButtonResult.OK, dialogParameters));
            });
        }
          public void OnDialogOpened(IDialogParameters parameters)
        {
         	// 刚打开界面时候的操作 可以获取父页面给子页面传的值
            MessageBox.Show($"窗口打开了!" + "\n" +
               
               $"{parameters.GetValue<string>("456")}"
               );
        }
 }
 去注册一些弹窗 App 或者模块加载的地方注册
   containerRegistry.RegisterDialog<AddTaskDialog>();
MainWindows 父级页面的ViewModel
 注入 _dialogService
 public Prism.Services.Dialogs.IDialogService _dialogService;
  void  showAddTaskDialog()
        {
            DialogParameters dialogParameters = new DialogParameters();
			// 要传递的参数
            dialogParameters.Add("456", "asdf");
             // 弹窗的名称 AddTaskDialog
            _dialogService.ShowDialog("AddTaskDialog", dialogParameters, DoDialogResult);
        }
        后续在绑定给 Command 就可以了

WPF Dev TreeListControl CheckBox 获取被选中的值

    <dxg:TreeListControl   DockPanel.Dock="Top"
                                       SelectionMode="Row"
                                    ItemsSource="{Binding AddTasks}"  
                                  
                                     
                                            >

                <dxg:TreeListControl.Columns   >
                    <dxg:TreeListColumn  FieldName="TaskName" Header="任务名称" MaxWidth="401" />
                dxg:TreeListControl.Columns>
                <dxg:TreeListControl.View  >
                    

                    dxg:TreeListView>
                dxg:TreeListControl.View>
Model
public class AddTaskModel
    {
        public int Id { get; set; }
        public string TaskName { get; set; }
        public int ParentId { get; set; }
         
        public bool IsSelect { get; set; }
    }
    private ObservableCollection<AddTaskModel> addTasks;
        public ObservableCollection<AddTaskModel> AddTasks
        {
            get => addTasks ?? (addTasks = new ObservableCollection<AddTaskModel>());
            set { SetProperty(ref addTasks, value); }
        }

你可能感兴趣的:(WPF,wpf,学习)