我想知道我是否可以从WPF中的已检查更改事件中获取Item源项目?
XAML
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<CheckBox IsChecked="{Binding Active, Mode=TwoWay}" Checked="CheckBox_Checked" HorizontalAlignment="Center"></CheckBox>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
示例C#(在正确答案的行上......我希望)
private void CheckBox_Checked(object sender, RoutedEventArgs e)
{
**// Its not e.source, most events it's e.item...but the checked event doesn't use this..**
Customer c = e.Source as Customer;
if(c != null)
.....
}
由于
答案 0 :(得分:0)
这样的事情,假设你没有关注MVVM
private void CheckBox_Checked(object sender, RoutedEventArgs e)
{
bool IsActive = (sender as CheckBox).IsChecked;
if(IsActive)
{
Active;
}
}
答案 1 :(得分:0)
你可以像Refernece
那样做视图模型
private bool _isactive;
public bool IsActive
{
get { return _isactive; }
set
{
_isactive = value;
RaisePropertyChanged(() => IsActive);
}
}
如果你想在mvvm中获取eventargs。使用Relay Command或Icommand
XAML
<CheckBox x:Name="chkbox" Command="{Binding CommandName}"
CommandParameter="{parameter}"/>
处理命令执行必要的操作。