In short, the control simply consists of four TextBoxes separated by three Labels containing the decimal separator.
A stripped down example:
<Border Name="borderMain" BorderThickness="1" BorderBrush="#FFA5ACB2">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="30" />
<ColumnDefinition Width="3" />
<ColumnDefinition Width="30" />
<ColumnDefinition Width="3" />
<ColumnDefinition Width="30" />
<ColumnDefinition Width="3" />
<ColumnDefinition Width="30" />
</Grid.ColumnDefinitions>
<TextBox Grid.Column="0" TabIndex="0" x:Name="TextOctet1" Text="{Binding Path=Octet1 />
<TextBlock Grid.Column="1" Text="." Width="5" />
<TextBox Grid.Column="2" TabIndex="1" x:Name="TextOctet2" Text="{Binding Path=Octet2 />
<TextBlock Grid.Column="3" Text="." Width="5" />
<TextBox Grid.Column="4" TabIndex="2" x:Name="TextOctet3" Text="{Binding Path=Octet3 />
<TextBlock Grid.Column="5" Text="." Width="5" />
<TextBox Grid.Column="6" TabIndex="3" x:Name="TextOctet4" Text="{Binding Path=Octet4 />
</Grid>
</Border>
Altogether, it's pretty simple to create. The code behind just needs to handle validation to keep your input in check and also navigation within the control.
Link to Source and binary: http://dl.dropbox.com/u/26136919/IPAddress.7z
Hi Josh,
ReplyDeletewhat is the type of license for your code?
No point in a license. Anyone can make this kind of stuff.
ReplyDeleteI added this dependency property so that the IPAddress is bindable ....
ReplyDeletepublic static readonly DependencyProperty IPAddressObjectProperty =
DependencyProperty.Register(
"IPAddressObject",
typeof(IPAddress),
typeof(IPAddressControl),
new PropertyMetadata(IPAddress.Parse("0.0.0.0"),
new PropertyChangedCallback(UpdateIPAddressObjectProperty)));
private static void UpdateIPAddressObjectProperty(DependencyObject ipAddressControl,
DependencyPropertyChangedEventArgs e)
{
(ipAddressControl as IPAddressControl).IPAddressObject = (IPAddress)e.NewValue;
}