1.DataGrid 单选事件
<DataGrid MinHeight="150"
AutoGenerateColumns="False"
CanUserAddRows="False"
IsReadOnly="True"
ItemsSource="{Binding DBG_ReserveData}"
SelectedItem="{Binding TCmsReserveNet}"
SelectionMode="Single">
<!-- *** -->
</DataGrid>
下面文本框中上一级菜单绑定DataSource 或者DataContent 绑定TCmsReserveNet,文本框绑定到里面的属性;
2.不用SelectedItem
<i:Interaction.Triggers>
<i:EventTrigger EventName="SelectionChanged">
<i:InvokeCommandAction Command="{Binding SelectedCmsReserveCommand}" />
</i:EventTrigger>
</i:Interaction.Triggers>
SelectedCmsReserveCommand:
public ICommand SelectedCmsReserveCommand { get { return new RelayCommand<string>(parameter => { if (DBG_ReserveData.CurrentItem != null) { //获取当前选中列 t_cms_reserveNet seCmsReserveNet = (t_cms_reserveNet)DBG_ReserveData.CurrentItem; fGuestName = seCmsReserveNet.GN; fBeginTime = seCmsReserveNet.BT; fEndTime = seCmsReserveNet.ET; fPhone = seCmsReserveNet.P; fManagerID = seCmsReserveNet.MID; fMoneyState = seCmsReserveNet.MS; fNote = seCmsReserveNet.N; fReserveState = seCmsReserveNet.RS; fRoomTypeID = seCmsReserveNet.RTID; fRoomID = seCmsReserveNet.FRID; fSubscription = seCmsReserveNet.ST; mTCmsReserve.fReserveID = seCmsReserveNet.RID; } }); } }