![](/img/trans.png)
[英]How to bind ListViewItem's IsSelected to property in Style
[英]How to bind IsSelected property of DataGrid row to a source property
我有一個 DataGrid 並將其項目源綁定到下面的類列表。 如何將數據網格行 IsSelected 屬性綁定到類 IsChecked 屬性?
public class DeckInt : INotifyPropertyChanged
{
public int id { get; set; }
public string name { get; set; }
public bool isChecked { get; set; }
public int Id { get { return id; } set { id = value; OnPropertyChanged(nameof(Id)); } }
/// <summary>
/// Group name of the weight item
/// </summary>
public string Name { get { return name; } set { name = value; OnPropertyChanged(nameof(Name)); } }
public bool IsChecked { get { return isChecked; } set { isChecked = value; OnPropertyChanged(nameof(IsChecked)); } }
public event PropertyChangedEventHandler PropertyChanged;
//When propert changes, notify
protected virtual void OnPropertyChanged(string propertyName = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}
您必須通過定義以DataGridRow
為目標的Style
來配置Binding
:
<DataGrid>
<DataGrid.RowStyle>
<Style TargetType="DataGridRow">
<Setter Property="IsSelected"
Value="{Binding IsChecked}" />
</DataGrid.RowStyle>
</DataGrid>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.