Advertisement
Guest User

WPF: Textbox and Binding to Double not able to type . on it

a guest
May 19th, 2015
510
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.67 KB | None | 0 0
  1. <Window x:Class="WpfApplication4.MainWindow"
  2.         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  3.         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  4.         xmlns:l="clr-namespace:WpfApplication4"
  5.         Title="MainWindow" Height="350" Width="525">
  6.     <Window.Resources>
  7.         <l:MyData x:Key="data" />
  8.     </Window.Resources>
  9.  
  10.     <Grid DataContext="{StaticResource ResourceKey=data}">
  11.         <Grid.ColumnDefinitions>
  12.             <ColumnDefinition Width="*"/>
  13.             <ColumnDefinition Width="5"/>
  14.             <ColumnDefinition Width="*"/>
  15.         </Grid.ColumnDefinitions>
  16.  
  17.         <TextBox Text="{Binding Path=MyProperty, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" VerticalAlignment="Top"></TextBox>
  18.  
  19.         <GridSplitter Grid.Column="1" Width="5" HorizontalAlignment="Stretch" Background="#FFFFFF" ResizeBehavior="PreviousAndNext"/>
  20.  
  21.         <TextBlock Grid.Column="2" Text="{Binding Path=MyProperty}" />
  22.  
  23.     </Grid>
  24.  
  25. </Window>
  26.  
  27.  
  28.  
  29.  
  30. using System;
  31. using System.ComponentModel;
  32. using System.Windows;
  33. using System.Windows.Controls;
  34.  
  35. namespace WpfApplication4
  36. {
  37.     /// <summary>
  38.     /// Interaction logic for MainWindow.xaml
  39.     /// </summary>
  40.     public partial class MainWindow : Window
  41.     {
  42.         public MainWindow()
  43.         {
  44.             InitializeComponent();
  45.         }
  46.     }
  47.  
  48.     public class MyData : INotifyPropertyChanged
  49.     {
  50.         private double myProperty;
  51.         public double MyProperty { get { return myProperty; } set { myProperty = value; Notify("MyProperty"); } }
  52.  
  53.         private void Notify(string p)
  54.         {
  55.             if(PropertyChanged != null)
  56.                 PropertyChanged(this, new PropertyChangedEventArgs(p));
  57.         }
  58.  
  59.         public MyData()
  60.         {
  61.             MyProperty = 0;
  62.         }
  63.  
  64.         public event PropertyChangedEventHandler PropertyChanged;
  65.     }
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement