|
Handle the focus lost event, then take the text of the textbox, and make sure it's a number, then use the Substring function to split it and insert your decimal.
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
You could use a masked edit box.
See here[^].
The funniest thing about this particular signature is that by the time you realise it doesn't say anything it's too late to stop reading it.
My latest tip/trick
Visit the Hindi forum here.
|
|
|
|
|
But these are paid ones how can I implement these in my wpf window application
|
|
|
|
|
|
You can add normal winforms controls (like maskedtextbox) to WPF.
From: Wrox, WPF Programmer’s Reference.
Before you can use a WindowsFormsHost, you must perform three steps:
1. Add a reference to the WindowsFormsIntegration library. In Visual Studio, you can open the
Project menu, select “Add Reference,” and select the library from the .NET tab on the Add
Reference dialog. In Expression Blend, you can open the Project menu, select Add Reference,
and then browse to the library file. On my system, it’s installed at C:\Program Files\
Reference Assemblies\Microsoft\Framework\v3.0\WindowsFormsIntegration.dll.
2. Add a reference to the System.Windows.Forms.dll library. Again, in Visual Studio, you can
use the Project menu’s Add Reference command and select the library from the resulting dialog.
In Expression Blend, you can again use the Project menu’s Add Reference command and
then browse to the library file. On my system, it’s installed at C:\Windows\Microsoft.NET\
Framework\v2.0.50727\System.Windows.Forms.dll.
3. Add a namespace declaration for the Windows Forms namespace to the top of the XAML
file. The declaration should look something like this:
xmlns:wf=”clr-namespace:System.Windows.Forms;assembly=System.Windows.Forms”
Hope this helps.
V.
|
|
|
|
|
Be aware, though, that any theming you apply to your textboxes will not apply. Also, focus management in WPF is problematic enough without adding Winforms into the mix. I'd avoid this option altogether and use a native WPF version instead as there are plenty of freely available solutions and this is an unnecessary step.
|
|
|
|
|
MM didn't know that. Thanks, I'll keep that in mind.
V.
|
|
|
|
|
I have a custom control, called 'YesNoButton'. It's two buttons, one says yes, one says no. I have a property, 'IsYes'. I'd like to bind to that property from my preferences class, so that I don't have to write any code to tie the two. Here's what I have:
<ctl:YesNoButton x:Name="showProgessOnDesktop" IsYes="{Binding Mode=TwoWay, Path=ShowOnDesktop, Source={x:Static c:Preferences.Instance}}"/>
is my XAML with my attempted binding. The code in the control is as follows ( created with help from the tab/tab auto generate thing )
public bool IsYes
{
get { return (bool)GetValue(IsYesProperty); }
set
{
SetValue(IsYesProperty, value);
no.Foreground = (value) ? Brushes.LightGray : Brushes.Black;
yes.Foreground = (value) ? Brushes.Black : Brushes.LightGray;
}
}
public static readonly DependencyProperty IsYesProperty =
DependencyProperty.Register("IsYes", typeof(bool), typeof(YesNoButton), new UIPropertyMetadata(false));
This code compiles and runs, so I assume that my binding is where the issue is. Preferences is a static class, with Instance as a static variable. If I set it in code, it works, internally, but does not change the UI on this form. If I set the default of the dependency property to 'true' it doesn't change the UI. If I set breakpoints, my setter is called when the value is set in code, and the values in the preferences class get set. My issue is entirely that I can't get the control to call the right getter on the preferences class to set itself up initially, that is, it always shows the same value and does not respect the value in the prefs class.
OK, I got it. I had to wait for the Loaded event, THEN I had to access the property to force it to read from the source, which then ran the code to set the state of the UI. If there's any way to make it read automatically, I'd love to know it.
Thanks for any help.
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
modified on Thursday, September 2, 2010 2:04 AM
|
|
|
|
|
Hi Christian Graus,
Included UpdateSourceTrigger="PropertyChanged" in binding. Like,
"showProgessOnDesktop" IsYes="{Binding Mode=TwoWay, Path=ShowOnDesktop, Source={x:Static c:Preferences.Instance}, UpdateSourceTrigger=PropertyChanged}"
HTH
|
|
|
|
|
I have a WPF that I'm trying to track down a problem to.
Basically when I have a list box and the user hits the "F" key it moves "currentselection" to the next listbox item in the list box. (this is really bad when you have a use trying to type into a textbox and they use the letter "F" and it moves to the next listboxitem)
I'm looked at the InputManager and a few other classes but I'm not exactly sure how to figure out what is happening to change the selected item.
Anyone know of a good way of tracking this down?
|
|
|
|
|
Hi Experts,
I am little new to Command binding so this might be a trivial question to many. I know that we can add Command bindings in xaml of a window and give its correspondng property in viewmodel. This viewmodel will be given to the DataContext of the window. Something like the following
--app.xaml.cs
mainWindow.DataContext = viewModel;
-- xaml
lt;Button Grid.Row="1" HorizontalAlignment="Right" Margin="0,3,18,3" Name="button1" Width="110"
Command="{Binding LoadCommand}">_Load</Button>
-- viewmodel
public ICommand LoadCommand
{
get
{
if (m_LoadCommand == null)
{
m_LoadCommand = new RelayCommand(param => CanLoad(), param => Load());
}
return m_LoadCommand;
}
}
Here the relaycommand is a class which implements ICommand interface. CanLoad() and Load() are the methods which will get executed for canexecute and execute action of the relaycommand respectively. This is the click event of the button which is handled.
I have a user control which has a custom routedevent registered in it and the user control is then used on a window. I am currently adding the event handler explicitly in code.
this.ucCustomEvent1.CustomClick += new RoutedEventHandler(ucCustomEvent_CustomClick);
this.AddHandler(UserControlThatCreatesEvent.CustomClickEvent, new RoutedEventHandler(ucCustomEvent_CustomClick));
I dont want to hook up the routedevent explicitly in code but in the xaml in the similar way as in the button example. I have uploaded the working sample code here for your perusal.
Please help!
Thanks in advance!
Regards,
Samar
|
|
|
|
|
Hi All,
I am able to solve this problem of mine. The link given here explain it. Just to keep it brief i did it using something similar to the following lines of code.
<c:MyUserControl local:CommandBehavior.RoutedEventName="MyCustomClick"
local:CommandBehavior.TheCommandToRun="{Binding MyViewModelCommand}"/>
CommandBehavior is a class given in the link above.
Thanks everyone for giving in your valuable time.
Regards,
Samar
|
|
|
|
|
Dear,
I'm reading Wrox WPF Programmers Reference Windows Presentation Foundation with C# 2010 and .NET 4
In chapter 16 - Themes and Skins I found following code that changes a skin at run time and attaches eventhandler for the different controls.
The Loadskin method is executed each time you select a skin from a context menu 'blue' or 'red'. I was wondering if the garbage collector removes the controls (and their handlers) at some point from memory. As I understood, the controls are re-generated each time, so if they're not collected, that could be a problem.
Note that it does say at some points 'code omitted', but the author did not mention my issue specifically so I doubt it would be there in the full code.
private void LoadSkin(string skin_file)
{
FrameworkElement element =
(FrameworkElement)Application.LoadComponent(new Uri(skin_file, UriKind.Relative));
this.Content = element;
Button btn;
Polygon pgn;
Rectangle rect;
Grid grd;
Ellipse ell;
switch (element.Tag.ToString())
{
case "Red":
btn = (Button)element.FindName("btnRepairDisk");
btn.Click += new RoutedEventHandler(btnRepairDisk_Click);
break;
case "Blue":
ell = (Ellipse)element.FindName("ellMove");
ell.MouseDown += new System.Windows.Input.MouseButtonEventHandler(rectMove_MouseDown);
grd = (Grid)element.FindName("grdExit");
grd.MouseDown += new System.Windows.Input.MouseButtonEventHandler(grdExit_MouseDown);
break;
}
}
thanks.
V.
|
|
|
|
|
Assuming you don't keep references to the controls elsewhere, I believe they would be collected as soon as the GC realized they were no longer a child of "this" (I assume the main window).
This wouldn't happen immediately, though... Just whenever the GC gets around to it.
|
|
|
|
|
Dear,
Thanks for your reply, it was more or less what I thought. Looks to me that it's better to do some cleaning up before changing large skins?
V.
|
|
|
|
|
Unless you plan on doing this frequently (As in, swapping skins automatically every few seconds), it shouldn't be a big deal. When the GC gets around to it, it'll trash any old ones lying around.
|
|
|
|
|
I have a demo about change skin of application. But when start application load style is ok. When I click a button to change style then my application stop. Please help me fix this error.
Here is my demo: http://www.kienthuccorp.com/research/ex.zip. Thank you very much
|
|
|
|
|
U S E T H E D E B U G G E R!!!
It comes with Visual Studio. Free.
Nobody here is going to download a file from someone they don't know.
.45 ACP - because shooting twice is just silly ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001
|
|
|
|
|
I have an example about wpf but it has an error. But I can not post or attache my example for everybody can help me. Please help me. Thank you very much.
|
|
|
|
|
You could always upload it to a service such as Windows Live, or Dropbox and then provide a link here.
|
|
|
|
|
Is it just a code snippet? If so, you can just paste it here with Encode "<" (and other HTML) characters when pasting checked. Then you can surround it in a PRE block and specify the lang attribute. With WPF XAML, you'd specify the lang as "XML". For example, typing this:
<pre lang="xml"><Window x:Class="MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Grid>
<TextBlock>Hello World</TextBlock>
</Grid>
</Window></pre>
Will produce this:
<Window x:Class="MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Grid>
<TextBlock>Hello World</TextBlock>
</Grid>
</Window>
And if you had some VB.Net, you'd specify the lang as "VB", like so:
<pre lang="vb">Class MainWindow
Public Sub DoStuff()
Dim x As Integer = 5
End Sub
End Class</pre>
Which would look like:
Class MainWindow
Public Sub DoStuff()
Dim x As Integer = 5
End Sub
End Class
If you click the "Preview" button before you post, you can make sure the code looks as you intended.
|
|
|
|
|
I am displaying date in my .XAML page
In .XAML.VB
e.g
variablename = date.now()
But it is returning my client date. i want to display server date.
One person's data is another person's program.
--J.Walia
|
|
|
|
|
You'd have to call a method on the server side through a WCF call. Be aware, though, that because of latency issues, the value that you receive would be the time that the server received and processed the request, and then by the time the message was transmitted back there would be extra latency involved.
|
|
|
|
|
how i can handle this??
One person's data is another person's program.
--J.Walia
|
|
|
|
|
I already told you. Use WCF.
|
|
|
|