wpf - 将DropDown值传递给WPF MVVM中的RelayCommand

标签 wpf xaml mvvm

这是我在XAML中的代码。

<telerik:RadComboBox ItemsSource="{Binding Items}" SelectedItem="{Binding SelectedItem}" ></telerik:RadComboBox>

<telerik:RadButton Name="BtnExportToPdf" Content="Export To PDF" Command="{Binding ExportToPDFClickCommand}"></telerik:RadButton>

下面是我在ViewModel中的RelayCommand
public ICommand ExportToPdfClickCommand
    {
        get
        {
            return new RelayCommand(ExportReportData);
        }
    }

我想将下拉值传递给中继命令。我怎样才能做到这一点 ?

最佳答案

为什么需要将所选项目传递给命令?
您的 View 模型已经具有该值:

SelectedItem =“{Binding SelectedItem}”

结果,只需在 View 模型中引用SelectedItem属性即可。

关于wpf - 将DropDown值传递给WPF MVVM中的RelayCommand,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26849582/

相关文章:

c# - 为什么 WPF 中的 UI 控件具有线程亲和性?

c# - 在 WPF 中使用带有大图像的图像源

c# - 类型 "..."的值不能添加到类型 'uielementcollection' 的集合或字典中

wpf - 实例化其他 XAML 文件中定义的对象

c# - 如何在样式中设置绑定(bind)?

wpf - 如何单向绑定(bind)到 materialDesign :ButtonProgressAssist. IsIndicatorVisible DependencyProperty

wpf - 如何使用 MVVM Light 拥有多个唯一的 ViewModel 实例?

c# - 升级到 Visual Studio 2015 会出现假错误

wpf - XAML:如何将 DependencyProperty 绑定(bind)到不同对象上同名的 C# 属性?

c# - 为什么这个绑定(bind)在 MVVM 中不起作用?