Skip to content

Instantly share code, notes, and snippets.

@SAAirey
Created September 18, 2014 18:16
Show Gist options
  • Save SAAirey/634ac11571b56bfd5165 to your computer and use it in GitHub Desktop.
Save SAAirey/634ac11571b56bfd5165 to your computer and use it in GitHub Desktop.
GridView row IsEnabled
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));
}
}
<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>
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