v1.06 — Fix product key paste across all 5 fields

- Use DataObject.Pasting handler to intercept paste before MaxLength truncation
- Full key paste (e.g. XXXXX-XXXXX-XXXXX-XXXXX-XXXXX) distributes across all boxes
- Works when pasting into any of the 5 fields

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
hariel1985
2026-03-31 06:20:29 +02:00
szülő 24b41b0e63
commit b412baaa5c
3 fájl változott, egészen pontosan 38 új sor hozzáadva és 26 régi sor törölve

Fájl megtekintése

@@ -9,9 +9,9 @@
<Company>InstaSoft Zrt.</Company> <Company>InstaSoft Zrt.</Company>
<Product>InstaSoft Office Tool</Product> <Product>InstaSoft Office Tool</Product>
<Copyright>Copyright (c) InstaSoft Zrt. 2026</Copyright> <Copyright>Copyright (c) InstaSoft Zrt. 2026</Copyright>
<Version>1.0.5</Version> <Version>1.0.6</Version>
<AssemblyVersion>1.0.5.0</AssemblyVersion> <AssemblyVersion>1.0.6.0</AssemblyVersion>
<FileVersion>1.0.5.0</FileVersion> <FileVersion>1.0.6.0</FileVersion>
<ApplicationManifest>app.manifest</ApplicationManifest> <ApplicationManifest>app.manifest</ApplicationManifest>
<LangVersion>latest</LangVersion> <LangVersion>latest</LangVersion>
</PropertyGroup> </PropertyGroup>

Fájl megtekintése

@@ -42,7 +42,7 @@
Foreground="{StaticResource TextSecondaryBrush}" Margin="0,-2,0,0"/> Foreground="{StaticResource TextSecondaryBrush}" Margin="0,-2,0,0"/>
</StackPanel> </StackPanel>
</StackPanel> </StackPanel>
<TextBlock Text="v1.05" HorizontalAlignment="Right" VerticalAlignment="Center" <TextBlock Text="v1.06" HorizontalAlignment="Right" VerticalAlignment="Center"
FontSize="12" Foreground="{StaticResource TextSecondaryBrush}"/> FontSize="12" Foreground="{StaticResource TextSecondaryBrush}"/>
</Grid> </Grid>
</Border> </Border>

Fájl megtekintése

@@ -27,20 +27,26 @@ namespace InstaSoftOfficeTool.Pages
_keyBoxes[i].Text = parts[i]; _keyBoxes[i].Text = parts[i];
} }
} }
// Intercept paste on all boxes
foreach (var box in _keyBoxes)
{
DataObject.AddPastingHandler(box, OnPaste);
}
} }
private void KeyBox_TextChanged(object sender, TextChangedEventArgs e) private void OnPaste(object sender, DataObjectPastingEventArgs e)
{ {
if (_suppressAutoTab) return; if (!e.DataObject.GetDataPresent(typeof(string))) return;
var tb = (TextBox)sender; var pasted = (string)e.DataObject.GetData(typeof(string));
var raw = tb.Text; var allAlphaNum = Regex.Replace(pasted, "[^A-Za-z0-9]", "");
// Only intercept if it looks like a full key (more than 5 chars)
if (allAlphaNum.Length <= 5) return;
e.CancelCommand(); // prevent default paste
// Detect full key paste (contains dash or longer than 5 chars with alphanumerics)
var allAlphaNum = Regex.Replace(raw, "[^A-Za-z0-9]", "");
if (allAlphaNum.Length > 5 && tb == _keyBoxes[0])
{
// Full key pasted — distribute across all boxes
_suppressAutoTab = true; _suppressAutoTab = true;
for (int i = 0; i < 5; i++) for (int i = 0; i < 5; i++)
{ {
@@ -55,9 +61,15 @@ namespace InstaSoftOfficeTool.Pages
_keyBoxes[4].Focus(); _keyBoxes[4].Focus();
_keyBoxes[4].CaretIndex = _keyBoxes[4].Text.Length; _keyBoxes[4].CaretIndex = _keyBoxes[4].Text.Length;
ValidationMessage.Visibility = Visibility.Collapsed; ValidationMessage.Visibility = Visibility.Collapsed;
return;
} }
private void KeyBox_TextChanged(object sender, TextChangedEventArgs e)
{
if (_suppressAutoTab) return;
var tb = (TextBox)sender;
var raw = tb.Text;
// Clean non-alphanumeric chars // Clean non-alphanumeric chars
var cleaned = Regex.Replace(raw, "[^A-Za-z0-9]", ""); var cleaned = Regex.Replace(raw, "[^A-Za-z0-9]", "");
if (cleaned != raw) if (cleaned != raw)