I want to dispalay some byte values and their binary values.like this:My UI.
my coding: this is the item source:
public MainWindow()
{
InitializeComponent();
ObservableCollection<MyRegs> regs = new ObservableCollection<MyRegs>()
{
new MyRegs(0x12),
new MyRegs(0x23),
new MyRegs(0x34)
};
RegsList.ItemsSource = regs;
}
this is custom data:
public class MyRegs
{
public MyRegs(byte val)
{
this.RegValue = val;
this.Bits = new bool[] { true, false, true, false, true, false, true, false };
}
private byte regValue;
public byte RegValue
{
get { return regValue; }
set
{
regValue = value;
}
}
private bool[] bits;
public bool[] Bits
{
get
{
return bits;
}
set
{
bits = value;
}
}
}
Xaml: by the way, Can I use a template to get those checkboxes
<Grid>
<ListView x:Name="RegsList">
<ListView.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<TextBox Text="{Binding Path=RegValue,Mode=TwoWay, Converter={StaticResource sResource1}}" HorizontalAlignment="Left" TextWrapping="Wrap"/>
<CheckBox IsChecked="{Binding Path=Bits[7],Mode=TwoWay}"/>
<CheckBox IsChecked="{Binding Path=Bits[6],Mode=TwoWay}"/>
<CheckBox IsChecked="{Binding Path=Bits[5],Mode=TwoWay}"/>
<CheckBox IsChecked="{Binding Path=Bits[4],Mode=TwoWay}"/>
<CheckBox IsChecked="{Binding Path=Bits[3],Mode=TwoWay}"/>
<CheckBox IsChecked="{Binding Path=Bits[2],Mode=TwoWay}"/>
<CheckBox IsChecked="{Binding Path=Bits[1],Mode=TwoWay}"/>
<CheckBox IsChecked="{Binding Path=Bits[0],Mode=TwoWay}"/>
</StackPanel>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
but when I check the CheckBox,it doesn't set Bits value.Why???
I haved used the ObservableCollection,it didn't work too.
If i use bool type not bool[] type,it workes.