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 x:Name="view"
                                
                                
                                  KeyFieldName="Id"
                                  ParentFieldName="ParentId"
                                  AutoWidth="True"
                                  ShowCheckboxes="True"
                                 SkipDisabledCheckBoxesOnRecursiveNodeChecking="True"
                                  // 配置 字段 对于 Model的 字段
                                 CheckBoxFieldName="IsSelect"
                                AllowPerPixelScrolling="True"
                                // 选择子项模式 可以自己配置试试
                                AllowRecursiveNodeChecking="True"
                               AllowScrollAnimation="True"
                               AllowPrintColumnHeaderImage="True" 
                                  ShowFixedTotalSummary="False"                                
                                 
                                  >

                    </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); }
        }
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值