Help with custom parts editor

Editors for WPF Forum

Posted 14 years ago by John Dunn
Version: 9.2.0515
Avatar
I'm attempting to create a custom parts editor that will allow entering of IP addresses. I've modified the SSN example but I can't get the MaskTextBox fields to show up - the '.'s between my octets do display. I don't get and exceptions or binding errors when running.

Since the parts editor stuff is pretty complicated, instead of my explaining what I've done, I've posted my code here which shows the issue.

Comments (3)

Posted 14 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi John,

Thanks for the sample. The issue is that you only have an implicit Style for IpAddressPartBase in your Resources.xaml. Implicit Styles are not inherited, so they will not be applied to your concrete types (i.e. IpAddressOctet1Part, IpAddressOctet2Part, etc). If you add the following code to the bottom of your Resources.xaml, then it should display as expected:
<Style x:Key="{x:Type ipP:IpAddressOctet1Part}" TargetType="{x:Type ipP:IpAddressOctet1Part}"
        BasedOn="{StaticResource {x:Type ipP:IpAddressPartBase}}" />
<Style x:Key="{x:Type ipP:IpAddressOctet2Part}" TargetType="{x:Type ipP:IpAddressOctet2Part}"
        BasedOn="{StaticResource {x:Type ipP:IpAddressPartBase}}" />
<Style x:Key="{x:Type ipP:IpAddressOctet3Part}" TargetType="{x:Type ipP:IpAddressOctet3Part}"
        BasedOn="{StaticResource {x:Type ipP:IpAddressPartBase}}" />
<Style x:Key="{x:Type ipP:IpAddressOctet4Part}" TargetType="{x:Type ipP:IpAddressOctet4Part}"
        BasedOn="{StaticResource {x:Type ipP:IpAddressPartBase}}" />
A few other notes we spotted:

1. In IpAddressOctetPart.cs on line 60, you will need to replace "Decrement(...)" with "Increment(...)".
2. In IpAddressPartGroup.cs on line 55, you will need to replace "IpAddressEditableParts.Octet1" with "convertParam".


Actipro Software Support

Posted 14 years ago by John Dunn
Avatar
Thanks. I had one more error

IpAddress.cs : Line 73 should be return string.Format("{0}.{1}.{2}.{3}", Octet1, Octet2, Octet3, Octet4);

Is there a way to get the control to move focus to the next part once a value greater than a certain value is entered? For example, if someone types '192' into the first part, the only thing that makes sense is to move focus to the next part. In theory, any value greater than 25 should move to the next part even if only 2 numbers are typed.
Posted 14 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi John,

What you can do is change the mask of the parts to be @"([0]{0,2}\d|[0]{0,1}\d{2}|1\d{2}|2[0-4]\d|25[0-5])". This better captures the type of data you want to allow to be entered. Then you can set IsFocusMovedOnTerminalMatches to true on your EditBox.

What this effectively does is when the user's input reaches an accept state that doesn't allow any additional input, then it will move focus.

The code we use to move the focus is similar to:
focusedElement.MoveFocus(new TraversalRequest(FocusNavigationDirection.Next));
So you should be able to cal that anytime you want. You can get the focused element using Keyboard.FocusedElement.


Actipro Software Support

The latest build of this product (v24.1.2) was released 21 days ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.