Created
May 22, 2009 12:28
-
-
Save jpoehls/116090 to your computer and use it in GitHub Desktop.
WPF Popup Keypad spike
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<Window x:Class="WpfApplication1.Window1" | |
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | |
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | |
Title="Popup Tester" Height="300" Width="300"> | |
<Window.Resources> | |
<Style TargetType="{x:Type TextBox}"> | |
<Setter Property="Margin" Value="10" /> | |
<EventSetter Event="GotKeyboardFocus" Handler="run_MouseEnter" /> | |
</Style> | |
<Style x:Key="KeypadBtn" TargetType="{x:Type Button}"> | |
<EventSetter Event="Click" Handler="key_Click" /> | |
</Style> | |
</Window.Resources> | |
<StackPanel> | |
<TextBox /> | |
<TextBox /> | |
<TextBox /> | |
<Popup Name="popLink" StaysOpen="True" Placement="Bottom" | |
PopupAnimation="Slide" AllowsTransparency="True"> | |
<Border BorderBrush="Beige" BorderThickness="2" Background="White"> | |
<Grid> | |
<Grid.ColumnDefinitions> | |
<ColumnDefinition Width="50" /> | |
<ColumnDefinition Width="50" /> | |
<ColumnDefinition Width="50" /> | |
<ColumnDefinition Width="50" /> | |
</Grid.ColumnDefinitions> | |
<Grid.RowDefinitions> | |
<RowDefinition Height="50" /> | |
<RowDefinition Height="50" /> | |
<RowDefinition Height="50" /> | |
<RowDefinition Height="50" /> | |
</Grid.RowDefinitions> | |
<Button Content="7" Style="{StaticResource KeypadBtn}" Grid.Row="0" Grid.Column="0" /> | |
<Button Content="8" Style="{StaticResource KeypadBtn}" Grid.Row="0" Grid.Column="1" /> | |
<Button Content="9" Style="{StaticResource KeypadBtn}" Grid.Row="0" Grid.Column="2" /> | |
<Button Content="X" Style="{StaticResource KeypadBtn}" Grid.Row="0" Grid.Column="3" Grid.RowSpan="2" /> | |
<Button Content="4" Style="{StaticResource KeypadBtn}" Grid.Row="1" Grid.Column="0" /> | |
<Button Content="5" Style="{StaticResource KeypadBtn}" Grid.Row="1" Grid.Column="1" /> | |
<Button Content="6" Style="{StaticResource KeypadBtn}" Grid.Row="1" Grid.Column="2" /> | |
<Button Content="1" Style="{StaticResource KeypadBtn}" Grid.Row="2" Grid.Column="0" /> | |
<Button Content="2" Style="{StaticResource KeypadBtn}" Grid.Row="2" Grid.Column="1" /> | |
<Button Content="3" Style="{StaticResource KeypadBtn}" Grid.Row="2" Grid.Column="2" /> | |
<Button Content="Save" Style="{StaticResource KeypadBtn}" Grid.Row="2" Grid.Column="3" Grid.RowSpan="2" /> | |
<Button Content="0" Style="{StaticResource KeypadBtn}" Grid.Row="3" Grid.Column="0" Grid.ColumnSpan="2" /> | |
<Button Content="." Style="{StaticResource KeypadBtn}" Grid.Row="3" Grid.Column="2" /> | |
</Grid> | |
</Border> | |
</Popup> | |
</StackPanel> | |
</Window> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Windows; | |
using System.Windows.Controls; | |
using System.Windows.Data; | |
using System.Windows.Documents; | |
using System.Windows.Input; | |
using System.Windows.Media; | |
using System.Windows.Media.Imaging; | |
using System.Windows.Navigation; | |
using System.Windows.Shapes; | |
using System.Diagnostics; | |
namespace WpfApplication1 | |
{ | |
/// <summary> | |
/// Interaction logic for Window1.xaml | |
/// </summary> | |
public partial class Window1 : Window | |
{ | |
public Window1() | |
{ | |
InitializeComponent(); | |
} | |
private TextBox targetTextbox; | |
private void run_MouseEnter(object sender, KeyboardEventArgs e) | |
{ | |
popLink.IsOpen = false; | |
popLink.PlacementTarget = (UIElement)e.Source; | |
popLink.Placement = System.Windows.Controls.Primitives.PlacementMode.Bottom; | |
popLink.IsOpen = true; | |
targetTextbox = sender as TextBox; | |
} | |
private void lnk_Click(object sender, RoutedEventArgs e) | |
{ | |
popLink.IsOpen = false; | |
targetTextbox = null; | |
} | |
private void key_Click(object sender, RoutedEventArgs e) | |
{ | |
Button btn = (Button)e.OriginalSource; | |
string s = btn.Content.ToString(); | |
if (s == "X" || s == "Save") | |
{ | |
popLink.IsOpen = false; | |
targetTextbox = null; | |
} | |
else | |
{ | |
targetTextbox.Text += s; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment