Skip to content

Commit

Permalink
Update min/max BytePerLine. Fix state on BytePerLine changing
Browse files Browse the repository at this point in the history
  • Loading branch information
Derek Tremblay committed Jan 4, 2018
1 parent c6226f6 commit 3c989fb
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 11 deletions.
30 changes: 19 additions & 11 deletions WPFHexaEditor.Control/HexaEditor.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1483,8 +1483,7 @@ public void SetPosition(long position, long byteLenght)
/// Get the line number of position in parameter
/// </summary>
public double GetLineNumber(long position) => position / BytePerLine;



/// <summary>
/// Get the column number of the position
/// </summary>
Expand Down Expand Up @@ -2182,18 +2181,27 @@ public int BytePerLine
BytePerLine_CoerceValue));

private static object BytePerLine_CoerceValue(DependencyObject d, object baseValue) =>
(int) baseValue < 8 ? 8 : ((int) baseValue > 32 ? 32 : baseValue);
(int) baseValue < 1 ? 1 : ((int) baseValue > 64 ? 64 : baseValue);

private static void BytePerLine_PropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
if (d is HexEditor ctrl && e.NewValue != e.OldValue)
{
//refresh
ctrl.UpdateScrollBar();
ctrl.BuildDataLines(ctrl.MaxVisibleLine, true);
ctrl.RefreshView(true);
ctrl.UpdateHeader(true);
}
if (!(d is HexEditor ctrl) || e.NewValue == e.OldValue) return;

//Get previous state
var firstPos = ctrl.FirstVisibleBytePosition;
var startPos = ctrl.SelectionStart;
var stopPos = ctrl.SelectionStop;

//refresh
ctrl.UpdateScrollBar();
ctrl.BuildDataLines(ctrl.MaxVisibleLine, true);
ctrl.RefreshView(true);
ctrl.UpdateHeader(true);

//Set previous state
ctrl.SetPosition(firstPos);
ctrl.SelectionStart = startPos;
ctrl.SelectionStop = stopPos;
}

#endregion
Expand Down
2 changes: 2 additions & 0 deletions WPFHexaEditorExample/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@
</MenuItem>

<MenuItem Click="TESTMenuItem_Click" Header="TEST" />
<control:HexBox x:Name="hbBSL" Height="23" ToolTip="ByteShiftLeft test"/>
</Menu>

<control:HexEditor
Expand All @@ -236,6 +237,7 @@
ApplicationName="Wpf Hexeditor control sample"
BorderThickness="1"
ByteGrouping="FourByte"
ByteShiftLeft="{Binding LongValue, ElementName=hbBSL, UpdateSourceTrigger=PropertyChanged}"
ByteSpacerPositioning="HexBytePanel"
ByteSpacerVisualStyle="Dash"
ByteSpacerWidthTickness="Normal"
Expand Down

0 comments on commit 3c989fb

Please sign in to comment.