I want to create a WPF control that allows to manipulate specific bits in a Byte (the markup is attached to the bottom of this post).
It should be used as follows
<ns:BitManipulator BitByte={Binding Path=...} />
but I cannot figure out how to organise (Multi-)Bindings to keep the following three values the same: a) Byte-Value in the Model that BitByte will be bound to b) Byte-Value of BitByte which either should update its value if either the model's value or the BitVector's value changes c) Bit-Representation of BitByte in the TextBoxes named order_i
Any hint appreciated
XAML
<UserControl x:Class="WpfLib.StackOverflow.BitManipulator"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<TextBox Name="order_0" Grid.Column="0" />
<TextBox Name="order_1" Grid.Column="1" />
<TextBox Name="order_2" Grid.Column="2" />
<TextBox Name="order_3" Grid.Column="3" />
<TextBox Name="order_4" Grid.Column="4" />
<TextBox Name="order_5" Grid.Column="5" />
<TextBox Name="order_6" Grid.Column="6" />
<TextBox Name="order_8" Grid.Column="7" />
</Grid>
</UserControl>
C# Code behind
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Markup;
namespace WpfLib.StackOverflow
{
[ContentProperty("BitByte")]
public partial class BitManipulator : UserControl
{
public static DependencyProperty BitByteProperty =
DependencyProperty.Register
(
"BitByte",
typeof(Byte),
typeof(BitManipulator),
new PropertyMetadata(null)
);
public BitManipulator()
{
InitializeComponent();
}
public Byte BitByte
{
get { return (Byte)GetValue(BitByteProperty); }
set { SetValue(BitByteProperty, value); }
}
}
}