silverlight MVVM在radioBox选择上检索datagrid所选行

silverlight MVVM在radioBox选择上检索datagrid所选行,silverlight,mvvm,datagrid,Silverlight,Mvvm,Datagrid,我有一个对话框填充网格行,我想在ViewModel的单选按钮上选择特定的网格行数据 using System; using System.Net; using System.Windows; using System.Windows.Controls; using System.Windows.Documents; using System.Windows.Ink; using System.Windows.Input; using System.Windows.Media; using Sys

我有一个对话框填充网格行,我想在ViewModel的单选按钮上选择特定的网格行数据

using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Collections.Generic;
using LMS.Server.DataAccess;
using System.Collections.ObjectModel;
using LMS.Client.Commanding;
using System.ComponentModel;

namespace LMS.Client.Model
{
    public class CampaignSearchResultsViewModel : ViewModelBase
    {

        public CampaignSearchResultsViewModel(List<Lead> obj)
        {
            foreach(Lead lead in obj)
            {
                SelectedLead = lead;
            }
        }

        public CampaignSearchResultsViewModel()
        {

            this.Commands.Add("CheckedCommand", new ActionCommand<Lead>(CheckIt));

            _leads = new ObservableCollection<Lead>();
            // this.icv=System.Windows.Data.CollectionViewSource.SourceProperty(_leads);
            //_leads.Add(new Lead { FirstName = "Neeraj", LastName = "Verma" });
            //_leads.Add(new Lead { FirstName = "Tarun", LastName = "Singh" });
        }


        private void CheckIt(Lead lead)
        {
            SelectedLead = lead;
            LeadViewModel lmv = new LeadViewModel(this);

            var x = SelectedLead;
            CampaignSearchResultsViewModel vm = new CampaignSearchResultsViewModel();

        }



        #region Private
        private ObservableCollection<Lead> _leads;

        public bool IsChecked { get; set; }

        private ICommand _checkedCommand;
        private object _testProperty;

        private Lead _selectedLead;

        private ICollectionView icv;

        #endregion

        private ICommand _checkedRadioCommand;
        private bool _inboundChecked;


        #region Properties
        public ObservableCollection<Lead> Leads
        {
            get { return _leads; }
            set
            {
                _leads = value;
                FirePropertyChanged("Leads");
            }
        }

        public Lead SelectedLead
        {
            get { return _selectedLead; }
            set { _selectedLead = value; }
        }

        public ICommand CheckedCommand
        {
            get
            {
                return Commands["CheckedCommand"];
            }
        }

        public bool InboundChecked
        {
            get
            {
                return _inboundChecked;
            }
            private set
            {
                if (_inboundChecked != value)
                {
                    _inboundChecked = value;
                    FirePropertyChanged("InboundChecked");
                }
            }
        }

        #endregion
    }
}
这是我的Xaml

<cc:DialogBase xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk"  x:Class="LMS.Client.View.CampaignSearchResultsDialog"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:cc="clr-namespace:LMS.Client.View;assembly=LMS.Client.Common"
    mc:Ignorable="d"
    d:DesignHeight="300" d:DesignWidth="400"
    xmlns:attach="clr-namespace:LMS.Client.Model.ViewModels.AttachedProperties;assembly=LMS.Client.Model"
    xmlns:converter="clr-namespace:LMS.Client.Model.ViewModels.Converters;assembly=LMS.Client.Model"
    xmlns:model="clr-namespace:LMS.Client.Model;assembly=LMS.Client.Common">
    <cc:DialogBase.Resources>
        <converter:DataContextFinderFromControl x:Key="dataContextFinder"/>
        <model:ViewModelSource Source="{Binding}" x:Name="viewModel"/>
    </cc:DialogBase.Resources>
    <Grid x:Name="LayoutRoot" Background="White" Height="300" Width="600">

        <sdk:DataGrid AutoGenerateColumns="False" Grid.Column="0" Grid.Row="0" 
                      ItemsSource="{Binding Path=Leads}"
                    SelectedItem="{Binding Path=SelectedLead,Mode=TwoWay}" Name="dgSearchResult"
                    Style="{StaticResource DataGridStyle}">
            <sdk:DataGrid.Columns>
                <sdk:DataGridTemplateColumn Header="Select">
                    <sdk:DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>

                            <RadioButton Content="Test" Style="{StaticResource SemiRadioButtonStyle}" GroupName="Lead"
                                         IsEnabled="True" Command="{Binding Path= CheckedCommand}" IsChecked="{Binding InboundChecked,Mode=TwoWay}"/>

                        </DataTemplate>
                    </sdk:DataGridTemplateColumn.CellTemplate>
                </sdk:DataGridTemplateColumn>


        </sdk:DataGrid>

        <StackPanel Width="300" Height="50" Background="White">
            <Grid Height="50">

            </Grid>
        </StackPanel>

    </Grid>
</cc:DialogBase>

以及ViewModel

using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Collections.Generic;
using LMS.Server.DataAccess;
using System.Collections.ObjectModel;
using LMS.Client.Commanding;
using System.ComponentModel;

namespace LMS.Client.Model
{
    public class CampaignSearchResultsViewModel : ViewModelBase
    {

        public CampaignSearchResultsViewModel(List<Lead> obj)
        {
            foreach(Lead lead in obj)
            {
                SelectedLead = lead;
            }
        }

        public CampaignSearchResultsViewModel()
        {

            this.Commands.Add("CheckedCommand", new ActionCommand<Lead>(CheckIt));

            _leads = new ObservableCollection<Lead>();
            // this.icv=System.Windows.Data.CollectionViewSource.SourceProperty(_leads);
            //_leads.Add(new Lead { FirstName = "Neeraj", LastName = "Verma" });
            //_leads.Add(new Lead { FirstName = "Tarun", LastName = "Singh" });
        }


        private void CheckIt(Lead lead)
        {
            SelectedLead = lead;
            LeadViewModel lmv = new LeadViewModel(this);

            var x = SelectedLead;
            CampaignSearchResultsViewModel vm = new CampaignSearchResultsViewModel();

        }



        #region Private
        private ObservableCollection<Lead> _leads;

        public bool IsChecked { get; set; }

        private ICommand _checkedCommand;
        private object _testProperty;

        private Lead _selectedLead;

        private ICollectionView icv;

        #endregion

        private ICommand _checkedRadioCommand;
        private bool _inboundChecked;


        #region Properties
        public ObservableCollection<Lead> Leads
        {
            get { return _leads; }
            set
            {
                _leads = value;
                FirePropertyChanged("Leads");
            }
        }

        public Lead SelectedLead
        {
            get { return _selectedLead; }
            set { _selectedLead = value; }
        }

        public ICommand CheckedCommand
        {
            get
            {
                return Commands["CheckedCommand"];
            }
        }

        public bool InboundChecked
        {
            get
            {
                return _inboundChecked;
            }
            private set
            {
                if (_inboundChecked != value)
                {
                    _inboundChecked = value;
                    FirePropertyChanged("InboundChecked");
                }
            }
        }

        #endregion
    }
}
使用系统;
Net系统;
使用System.Windows;
使用System.Windows.Controls;
使用System.Windows.Documents;
使用System.Windows.Ink;
使用System.Windows.Input;
使用System.Windows.Media;
使用System.Windows.Media.Animation;
使用System.Windows.Shapes;
使用System.Collections.Generic;
使用LMS.Server.DataAccess;
使用System.Collections.ObjectModel;
使用LMS.Client.Commanding;
使用系统组件模型;
名称空间LMS.Client.Model
{
公共类活动SearchResultsViewModel:ViewModelBase
{
公共活动搜索结果视图模型(列表对象)
{
foreach(obj中的铅)
{
SelectedLead=lead;
}
}
公共活动SearchResultsViewModel()
{
this.Commands.Add(“CheckedCommand”,newactionCommand(CheckIt));
_leads=新的ObservableCollection();
//this.icv=System.Windows.Data.CollectionViewSource.SourceProperty(_leads);
//_leads.Add(新Lead{FirstName=“Neeraj”,LastName=“Verma”});
//_leads.Add(新Lead{FirstName=“Tarun”,LastName=“Singh”});
}
私人作废支票(牵头人)
{
SelectedLead=lead;
LeadViewModel lmv=新的LeadViewModel(本);
var x=选定的潜在客户;
活动搜索结果视图模型vm=新的活动搜索结果视图模型();
}
#地区私人
私人可观察收集线索;
已检查公共布尔值{get;set;}
专用ICommand_checkedCommand;
私有对象_testProperty;
私人Lead _selectedLead;
私人ICollectionView icv;
#端区
专用ICommand _checkedRadioCommand;
私人边界检查;
#区域属性
公开收集线索
{
获取{返回_leads;}
设置
{
_领导=价值;
火属性变更(“导线”);
}
}
公共引导选择引导
{
获取{return\u selectedLead;}
设置{u selectedLead=value;}
}
公共ICommand checked命令
{
得到
{
返回命令[“CheckedCommand”];
}
}
公共边界检查
{
得到
{
返回_inboundChecked;
}
专用设备
{
如果(_inboundChecked!=值)
{
_inboundChecked=值;
改变了防火性能(“内部检查”);
}
}
}
#端区
}
}
我无法在单选按钮上映射网格中的数据,请告诉我缺少的位置

Add CommandParameter=“{Binding}”,以便您可以在视图模型中获取案例中的整个对象(Lead)。然后可以将此对象设置为选定项。所以你可以像这样修改你的代码

 <RadioButton Content="Test" Style="{StaticResource SemiRadioButtonStyle}" GroupName="Lead"
                                     IsEnabled="True" Command="{Binding Path= CheckedCommand}"  CommandParameter="{Binding}" IsChecked="{Binding InboundChecked,Mode=TwoWay}"/>


然后在您的代码中,您可以将CommandParameter强制转换为Lead,并将此对象设置为SelectedLead

您是否能够通过命令绑定检索命令参数?我不明白您的意思,如果我将调试器放在方法上,我无法获取它。。请联系我skype如果你能帮助我,我的id是bs24neeraj,这是紧急的,我必须提交代码今天