I have a ListView which is bind dynamically to a list of object of the same type.
The object have a boolean value.
There a ListView column which display a checkbox instead of the "true" and "false" normal value for that specific property.
Is there a way to set that checkbox readonly ? otherwise is there a way to tell that the click is coming from this specific row in the events "checked" and "unchecked" which execute a method in code behind ?
Thanks!
You can make any control readonly by setting IsHitTestVisible and Focusable to false.
XAML:
<Window x:Class="WpfApplication1.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:WpfApplication1="clr-namespace:WpfApplication1">
<StackPanel>
<ListView ItemsSource="{Binding}">
<ListView.View>
<GridView>
<GridViewColumn Header="Name" DisplayMemberBinding="{Binding Path=Name}" />
<GridViewColumn Header="Is Valid">
<GridViewColumn.CellTemplate>
<DataTemplate>
<CheckBox IsChecked="{Binding Path=IsValid}" IsHitTestVisible="False" Focusable="False" />
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
</GridView>
</ListView.View>
</ListView>
</StackPanel>
</Window>
Code behind:
using System.Collections.Generic;
namespace WpfApplication1
{
public partial class Window1
{
public Window1()
{
InitializeComponent();
List<DataItem> data = new List<DataItem>();
data.Add(new DataItem() { Name = "AAA", IsValid = true });
data.Add(new DataItem() { Name = "BBB" });
DataContext = data;
}
public class DataItem
{
public string Name { get; set; }
public bool IsValid { get; set; }
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With