Skip to content
This repository has been archived by the owner on Jun 4, 2018. It is now read-only.

Commit

Permalink
Use attachable properties for updating source on enter.
Browse files Browse the repository at this point in the history
  • Loading branch information
jrick committed Feb 19, 2016
1 parent 677c69f commit 0b9b3d7
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 39 deletions.
4 changes: 3 additions & 1 deletion Paymetheus/CreateAccountDialogView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
<StackPanel>
<Label Content="Create account" FontSize="18"/>
<Label Content="Account name:"/>
<TextBox Name="textBox" Text="{Binding AccountName, UpdateSourceTrigger=Default}" Margin="6 2" Padding="2" KeyDown="textBox_KeyDown"/>
<TextBox Name="textBox" Margin="6 2" Padding="2"
Text="{Binding AccountName, Mode=OneWayToSource}"
local:BindingProperties.UpdateSourceOnEnterProperty="TextBox.Text"/>
<Label Content="Private passphrase:"/>
<PasswordBox Name="passphraseTextBox" PasswordChanged="passphraseTextBox_PasswordChanged" Margin="6 2" Padding="2"/>
</StackPanel>
Expand Down
12 changes: 0 additions & 12 deletions Paymetheus/CreateAccountDialogView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,6 @@ public CreateAccountDialogView()
InitializeComponent();
}

private void textBox_KeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.Enter)
{
var textBox = (TextBox)sender;
var prop = TextBox.TextProperty;

var binding = BindingOperations.GetBindingExpression(textBox, prop);
binding?.UpdateSource();
}
}

private void passphraseTextBox_PasswordChanged(object sender, RoutedEventArgs e)
{
if (DataContext != null)
Expand Down
4 changes: 3 additions & 1 deletion Paymetheus/ImportDialogView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
<StackPanel>
<Label Content="Import key" FontSize="18"/>
<Label Content="Private key (WIF):"/>
<TextBox Name="textBox" Text="{Binding PrivateKeyWif, UpdateSourceTrigger=Default}" Margin="6 2" Padding="2" KeyDown="textBox_KeyDown"/>
<TextBox Name="textBox" Margin="6 2" Padding="2"
Text="{Binding PrivateKeyWif, Mode=OneWayToSource}"
local:BindingProperties.UpdateSourceOnEnterProperty="TextBox.Text"/>
<Label Content="Private passphrase:"/>
<PasswordBox PasswordChanged="PasswordBox_PasswordChanged" Margin="6 2" Padding="2"/>
<CheckBox Content="Rescan blockchain for unspent outputs" IsChecked="{Binding Rescan}" Margin="6"/>
Expand Down
12 changes: 0 additions & 12 deletions Paymetheus/ImportDialogView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,6 @@ public ImportDialogView()
InitializeComponent();
}

private void textBox_KeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.Enter)
{
var textBox = (TextBox)sender;
var prop = TextBox.TextProperty;

var binding = BindingOperations.GetBindingExpression(textBox, prop);
binding?.UpdateSource();
}
}

private void PasswordBox_PasswordChanged(object sender, RoutedEventArgs e)
{
if (DataContext != null)
Expand Down
4 changes: 3 additions & 1 deletion Paymetheus/RenameAccountDialogView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@
</TextBlock>
</Label>
<Label Content="New name:"/>
<TextBox Name="textBox" Text="{Binding NewAccountName, UpdateSourceTrigger=Default}" Margin="6 2" Padding="2" KeyDown="textBox_KeyDown"/>
<TextBox Name="textBox" Margin="6 2" Padding="2"
Text="{Binding NewAccountName, Mode=OneWayToSource}"
local:BindingProperties.UpdateSourceOnEnterProperty="TextBox.Text"/>
</StackPanel>
</DockPanel>
</UserControl>
12 changes: 0 additions & 12 deletions Paymetheus/RenameAccountDialogView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,5 @@ public RenameAccountDialogView()
{
InitializeComponent();
}

private void textBox_KeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.Enter)
{
var textBox = (TextBox)sender;
var prop = TextBox.TextProperty;

var binding = BindingOperations.GetBindingExpression(textBox, prop);
binding?.UpdateSource();
}
}
}
}

0 comments on commit 0b9b3d7

Please sign in to comment.