Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I set up the following example, which demonstrates the binding using a value converter.</p> <p>Here is the Window1.xaml.cs:</p> <pre><code>private ObservableCollection&lt;ByteData&gt; _collection = new ObservableCollection&lt;ByteData&gt;(); public Window1() { InitializeComponent(); _collection.Add(new ByteData(new byte[] { 12, 54 })); _collection.Add(new ByteData(new byte[] { 1, 2, 3, 4, 5 })); _collection.Add(new ByteData(new byte[] { 15 })); } public ObservableCollection&lt;ByteData&gt; ObservableCollection { get { return _collection; } } public class ByteData { byte[] _data; public ByteData(byte[] data) { _data = data; } public byte[] Data { get { return _data; } set { _data = value; } } } </code></pre> <p>Here is the Window1.xaml:</p> <pre><code>&lt;Window x:Class="TestWpfApplication.Window1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="clr-namespace:TestWpfApplication" xmlns:sys="clr-namespace:System;assembly=mscorlib" Title="Window1" Height="300" Width="300" DataContext="{Binding RelativeSource={RelativeSource Self}}"&gt; &lt;Window.Resources&gt; &lt;local:ByteToStringConverter x:Key="byteToStringConverter"/&gt; &lt;/Window.Resources&gt; &lt;StackPanel&gt; &lt;ListView ItemsSource="{Binding ObservableCollection}"&gt; &lt;ListView.ItemTemplate&gt; &lt;DataTemplate&gt; &lt;TextBox Width="200" Text="{Binding Path=Data, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, Converter={StaticResource byteToStringConverter}}"/&gt; &lt;/DataTemplate&gt; &lt;/ListView.ItemTemplate&gt; &lt;/ListView&gt; &lt;/StackPanel&gt; </code></pre> <p></p> <p>And here is the value converter:</p> <pre><code>public class ByteToStringConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { byte[] data = (byte[])value; StringBuilder byteString = new StringBuilder(); int idx; for (idx = 0; idx &lt; data.Length - 1; idx++) { byteString.AppendFormat("{0}, ", data[idx]); } byteString.Append(data[idx]); return byteString.ToString(); } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { // If you want your byte-data to be editable in the textboxes, // this will need to be implemented. return null; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload