-
-
Save SAAirey/634ac11571b56bfd5165 to your computer and use it in GitHub Desktop.
GridView row IsEnabled
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class DreadPiratePeterIsEnabledItem | |
: INotifyPropertyChanged | |
{ | |
private string _pirateName; | |
public string PirateName | |
{ | |
get { return _pirateName; } | |
set | |
{ | |
if (_pirateName != value) | |
{ | |
_pirateName = value; | |
OnPropertyChanged(); | |
} | |
} | |
} | |
private bool _isEnabled; | |
public bool IsEnabled | |
{ | |
get { return _isEnabled; } | |
set | |
{ | |
if (_isEnabled != value) | |
{ | |
_isEnabled = value; | |
OnPropertyChanged(); | |
} | |
} | |
} | |
public event PropertyChangedEventHandler PropertyChanged; | |
[NotifyPropertyChangedInvocator] | |
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null) | |
{ | |
PropertyChangedEventHandler handler = PropertyChanged; | |
if (handler != null) handler(this, new PropertyChangedEventArgs(propertyName)); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<Window x:Class="GridViewTesting.MainWindow" | |
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | |
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | |
Title="MainWindow" Height="350" Width="525" | |
DataContext="{Binding RelativeSource={RelativeSource Self}}"> | |
<Grid> | |
<ListView ItemsSource="{Binding Pirates}"> | |
<ListView.ItemContainerStyle> | |
<Style TargetType="{x:Type ListViewItem}"> | |
<Setter Property="IsEnabled" Value="{Binding IsEnabled}" /> | |
</Style> | |
</ListView.ItemContainerStyle> | |
<ListView.View> | |
<GridView> | |
<GridViewColumn Header="Pirate name" DisplayMemberBinding="{Binding PirateName}" /> | |
</GridView> | |
</ListView.View> | |
</ListView> | |
</Grid> | |
</Window> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public partial class MainWindow : Window | |
{ | |
public ObservableCollection<DreadPiratePeterIsEnabledItem> Pirates { get; private set; } | |
public MainWindow() | |
{ | |
var piratesList = new List<DreadPiratePeterIsEnabledItem> | |
{ | |
new DreadPiratePeterIsEnabledItem | |
{ | |
PirateName = "Peter", | |
IsEnabled = true | |
}, | |
new DreadPiratePeterIsEnabledItem | |
{ | |
PirateName = "Sean", | |
IsEnabled = false | |
} | |
}; | |
Pirates = new ObservableCollection<DreadPiratePeterIsEnabledItem>(piratesList); | |
InitializeComponent(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment