Laden und Binden- GridView trifft RSS

Nachdem nun alles bereit ist für geregelten Verkehr wende ich mich der Praxis zu. Ums ganz einfach zu halten kommt die Syndication Helfer aus Windows.Web.Syndication zum Einsatz. Diese gibt's auch in .net 4 und Silverlight. Man spart sich einfach ne Menge Code. Das ganz besondere hier ist die Asynchrone Ausführung. Statt einer Delegate oder Lambda Funktion reicht AWAIT. Die aufrufende Funktion muss mit ASYNC gekennzeichnet sein. Intern wird dann der lang laufende Code im Background Thread ausgeführt um den UI Thread nicht zu blockieren. Der Benutzer kann also weiter mit dem Programm arbeiten. Wenn die Aufgabe erledigt ist (hier der download) werden die Threads synchronisiert und die Daten in der UI aktualisiert. Dim feed As SyndicationFeed Private Async Function Button_Click_1(sender As Object, e As RoutedEventArgs) As Task Dim uri As Uri = New Uri("http://www.heise-marktplatz.de/system/RSS/category/7") Dim clt As SyndicationClient = New SyndicationClient() feed = Await clt.RetrieveFeedAsync(uri) Gridview1.ItemsSource = feed.Items End Function Das Gridview  enthält dann vorerst den Titel des RSS Eintrages in der Kachel. Da ein Feeditem ein relativ komplexes Element darstellen kann, wird nicht auf Title sondern auf den Text darin gebunden. Es könnte ja auch ein Attribut enthalten sein. Die Zuweisung des Property erfolgt wie in WPF oder Silverlight mit der Binding Syntax, Bis auf Inputvalidation (ValidatesonException) und den Formatern (StringFormat) ist es recht ähnlich zu Silverlight XAML. <GridView HorizontalAlignment="Left" Margin="0,0,0,0" x:Name="Gridview1" > <GridView.ItemTemplate> <DataTemplate> <Canvas Width="200" Height="200" Background="DarkBlue"> <TextBlock Text="{Binding Title.Text}" Width="180" Canvas.Top="10" Canvas.Left="10" TextWrapping="Wrap"/> </Canvas> </DataTemplate> </GridView.ItemTemplate> </GridView> .csharpcode, .csharpcode pre { font-size: small; color: black; font-family: consolas, "Courier New", courier, monospace; background-color: #ffffff; /*white-space: pre;*/ } .csharpcode pre { margin: 0em; } .csharpcode .rem { color: #008000; } .csharpcode .kwrd { color: #0000ff; } .csharpcode .str { color: #006080; } .csharpcode .op { color: #0000c0; } .csharpcode .preproc { color: #cc6633; } .csharpcode .asp { background-color: #ffff00; } .csharpcode .html { color: #800000; } .csharpcode .attr { color: #ff0000; } .csharpcode .alt { background-color: #f4f4f4; width: 100%; margin: 0em; } .csharpcode .lnum { color: #606060; } Die Ausgabe im Windows 8 Simulator. Um das ganze clickbar zu machen wird ein HyperLinkButton verwendet. Die Url wird im Tag Attribut zugewiesen. <HyperlinkButton Tag="{Binding Links[0].Uri.OriginalString}" Click="hyperlinkclick"> <TextBlock Text="{Binding Title.Text}" Width="180" Canvas.Top="10" Canvas.Left="10" TextWrapping="Wrap"/> </HyperlinkButton> .csharpcode, .csharpcode pre { font-size: small; color: black; font-family: consolas, "Courier New", courier, monospace; background-color: #ffffff; /*white-space: pre;*/ } .csharpcode pre { margin: 0em; } .csharpcode .rem { color: #008000; } .csharpcode .kwrd { color: #0000ff; } .csharpcode .str { color: #006080; } .csharpcode .op { color: #0000c0; } .csharpcode .preproc { color: #cc6633; } .csharpcode .asp { background-color: #ffff00; } .csharpcode .html { color: #800000; } .csharpcode .attr { color: #ff0000; } .csharpcode .alt { background-color: #f4f4f4; width: 100%; margin: 0em; } .csharpcode .lnum { color: #606060; } Dann wird mit dem Launcher der Browser aufgerufen und die Url direkt angezeigt. Private Async Sub hyperlinkclick(sender As Object, e As RoutedEventArgs) Await Launcher.LaunchUriAsync(New Uri(sender.Tag)) End Sub .csharpcode, .csharpcode pre { font-size: small; color: black; font-family: consolas, "Courier New", courier, monospace; background-color: #ffffff; /*white-space: pre;*/ } .csharpcode pre { margin: 0em; } .csharpcode .rem { color: #008000; } .csharpcode .kwrd { color: #0000ff; } .csharpcode .str { color: #006080; } .csharpcode .op { color: #0000c0; } .csharpcode .preproc { color: #cc6633; } .csharpcode .asp { background-color: #ffff00; } .csharpcode .html { color: #800000; } .csharpcode .attr { color: #ff0000; } .csharpcode .alt { background-color: #f4f4f4; width: 100%; margin: 0em; } .csharpcode .lnum { color: #606060; } Hinweis: rund 20 % der WinRT API Funktionen erfordern den asynchronen Aufruf, Microsoft  gibt 50 ms als Grenzwert an, Wenn man dann im Code trotzdem ohne ASYNC den Funktionsaufruf durchführt wird im besten Fall ein Laufzeit Fehler erzeugt,

Windows 8 und localhost

In Vorbereitung auf meine nächsten Windows 8 WinRT Beispiele, habe ich mir Fiddler installiert. Den gibt es nun auch in einer .net 4 Version.  Das erspart eventuell die Installation eines älteren .NET Frameworks. Mit Fiddler kann man per Umleitung des HTTP Traffic an einen Proxy ( eben Fiddler) den Verkehr auf der Leitung analysieren. Das wollte ich so z.B. mit der Wetter APP machen. Ist aber nicht. So wie es aussieht unterbindet Windows 8 für METRO APP’s den Zugriff auf localhost. Damit ist auch das Funktionsprinzip eines Debugging Proxys vorerst mal sabotiert. Das wird auch den ein oder anderen lokalen WCF oder RIA  Service Nutzer noch schwer aufstoßen. Der Zugriff ist dann nicht möglich. Für Fiddler hat der Autor Eric Lawrence freundlicherweise ein Werkzeug gebaut, mit dem man die Sandbox Isolation des Appcontainers der APP aufheben kann. also einfach Haken bei Weather gesetzt, Fiddler starten und dann die METRO APP. Dann klappt's auch mit dem Netzwerk Scan. Die Funktion taucht dann auch im Fiddler unter Tools Win8 Loopback Excemptions auf. Misstrauisch wie ich bin, schaue ich auch gerne mal genauer hin. Ein bisschen viel oder? Der Grund lässt sich im Header auch schnell ermitteln Keine Kompression, kein GZIP und Deflate. Unter uns, einen REST Service ohne Kompression zu betreiben, die üblicherweise rund 2/3 der Datenmenge einspart ist beinahe schon fahrlässig. In der Doku nach etwas nicht vorhanden zu suchen, gestaltet sich als einigermaßen schwierig. Aus meinen Tests hat sich ergeben das man die Header explizit angeben muss. Dann geht auch GZIP und Deflate HTTP Kompression in WinRT. Dim http = New HttpClient(New HttpClientHandler() With {.AutomaticDecompression = DecompressionMethods.Deflate Or DecompressionMethods.GZip}) .csharpcode, .csharpcode pre { font-size: small; color: black; font-family: consolas, "Courier New", courier, monospace; background-color: #ffffff; /*white-space: pre;*/ } .csharpcode pre { margin: 0em; } .csharpcode .rem { color: #008000; } .csharpcode .kwrd { color: #0000ff; } .csharpcode .str { color: #006080; } .csharpcode .op { color: #0000c0; } .csharpcode .preproc { color: #cc6633; } .csharpcode .asp { background-color: #ffff00; } .csharpcode .html { color: #800000; } .csharpcode .attr { color: #ff0000; } .csharpcode .alt { background-color: #f4f4f4; width: 100%; margin: 0em; } .csharpcode .lnum { color: #606060; }

ListView gruppiert

Aufbauend auf einem vorigen WinRT Beispiel wird nun eine Master Detail oder auch Gruppe eingeführt. Dazu wird die Person um die Eigenschaft sex (Geschlecht) erweitert und dann danach gruppiert. Erschwerend kommt hinzu das nur männlich als wahres (true) Geschlecht definiert wird . Um aus dem boolschen Wert einen Text zu erhalten benötigt man dann noch einen Converter. Für die Gruppierung muss eine CollectionViewSource zwischen geschaltet werden. Beides per Deklaration im Resources Bereich. <UserControl.Resources> <my:conv1 x:Key="fmConverter"/> <CollectionViewSource x:Name="cvs1" IsSourceGrouped="true" > </CollectionViewSource> </UserControl.Resources> .csharpcode, .csharpcode pre { font-size: small; color: black; font-family: consolas, "Courier New", courier, monospace; background-color: #ffffff; /*white-space: pre;*/ } .csharpcode pre { margin: 0em; } .csharpcode .rem { color: #008000; } .csharpcode .kwrd { color: #0000ff; } .csharpcode .str { color: #006080; } .csharpcode .op { color: #0000c0; } .csharpcode .preproc { color: #cc6633; } .csharpcode .asp { background-color: #ffff00; } .csharpcode .html { color: #800000; } .csharpcode .attr { color: #ff0000; } .csharpcode .alt { background-color: #f4f4f4; width: 100%; margin: 0em; } .csharpcode .lnum { color: #606060; } Ganz wichtig ist das Attribut isSourceGrouped. Um diese Gruppe zu erzeugen wird ein LINQ Statement zwischen geschaltet. Dort gibt es die Möglichkeit zu gruppieren mit Groub py. Dim pers = New personen Dim q = From p In pers Group p By key = p.sex Into g = Group Select New GroupInfo(Of Boolean, person)(key, g) cvs1.Source = q Hier fallt natürlich auf, das die erzeugten Daten mit den Ursprungsdaten wenig gemein haben. Die Gruppe wird in einer Liste vom Typ Groupinfo abgelegt. Groupinfo ist eine eigene Klasse, die ich auch im wesentlichen kopiert habe um mir die aufwendige Implementierung des Codes zu ersparen. Public Class GroupInfo(Of TKey, TItem) 'interface required to show grouped data Implements IGrouping(Of TKey, TItem) Private _source As IEnumerable(Of TItem) Private _key As TKey 'takes a LINQ IGrouping and converts it to a GroupInfo Public Sub New(key As TKey, source As IEnumerable(Of TItem)) _key = key _source = source End Sub Private Function IEnumerable_GetEnumerator() As System.Collections.IEnumerator Implements System.Collections.IEnumerable.GetEnumerator Return _source.GetEnumerator End Function Public Function GetEnumerator() As IEnumerator(Of TItem) Implements IEnumerable(Of TItem).GetEnumerator Return _source.Cast(Of TItem).GetEnumerator() End Function Public ReadOnly Property key As TKey Implements IGrouping(Of TKey, TItem).Key Get Return _key End Get End Property End Class .csharpcode, .csharpcode pre { font-size: small; color: black; font-family: consolas, "Courier New", courier, monospace; background-color: #ffffff; /*white-space: pre;*/ } .csharpcode pre { margin: 0em; } .csharpcode .rem { color: #008000; } .csharpcode .kwrd { color: #0000ff; } .csharpcode .str { color: #006080; } .csharpcode .op { color: #0000c0; } .csharpcode .preproc { color: #cc6633; } .csharpcode .asp { background-color: #ffff00; } .csharpcode .html { color: #800000; } .csharpcode .attr { color: #ff0000; } .csharpcode .alt { background-color: #f4f4f4; width: 100%; margin: 0em; } .csharpcode .lnum { color: #606060; } Die fertige Windows 8 Anwendung   Der XAML Code benötigt ein Template für die Gruppe und eines für die Listen Einträge. Im Headertemplate wird aus dem true oder false des Key per Converter ein Text. <ListView HorizontalAlignment="Left" Margin="20,10,0,0" VerticalAlignment="Top" Width="342" ItemsSource="{Binding Source={StaticResource cvs1}}" > <ListView.GroupStyle> <GroupStyle> <GroupStyle.HeaderTemplate> <DataTemplate> <Grid Margin="7,7,0,0"> <Button Content="{Binding key,Converter={StaticResource fmConverter}}" /> </Grid> </DataTemplate> </GroupStyle.HeaderTemplate> </GroupStyle> </ListView.GroupStyle> <ListView.ItemTemplate> <DataTemplate> <StackPanel Orientation="Horizontal"> <TextBlock Text="{Binding name}" FontSize="20" Margin="10" FontWeight="Bold"/> <TextBlock Text="{Binding alter}" FontSize="20" Margin="10" FontWeight="Bold"/> </StackPanel> </DataTemplate> </ListView.ItemTemplate> </ListView> .csharpcode, .csharpcode pre { font-size: small; color: black; font-family: consolas, "Courier New", courier, monospace; background-color: #ffffff; /*white-space: pre;*/ } .csharpcode pre { margin: 0em; } .csharpcode .rem { color: #008000; } .csharpcode .kwrd { color: #0000ff; } .csharpcode .str { color: #006080; } .csharpcode .op { color: #0000c0; } .csharpcode .preproc { color: #cc6633; } .csharpcode .asp { background-color: #ffff00; } .csharpcode .html { color: #800000; } .csharpcode .attr { color: #ff0000; } .csharpcode .alt { background-color: #f4f4f4; width: 100%; margin: 0em; } .csharpcode .lnum { color: #606060; }   Zur Vollständigkeit halber der Converter. Public Class conv1 Implements IValueConverter Public Function Convert(value As Object, targetType As Type, parameter As Object, language As String) As Object Implements IValueConverter.Convert If value Then Return "maennlich" Else Return "weiblich" End If End Function Public Function ConvertBack(value As Object, targetType As Type, parameter As Object, language As String) As Object Implements IValueConverter.ConvertBack End Function End Class .csharpcode, .csharpcode pre { font-size: small; color: black; font-family: consolas, "Courier New", courier, monospace; background-color: #ffffff; /*white-space: pre;*/ } .csharpcode pre { margin: 0em; } .csharpcode .rem { color: #008000; } .csharpcode .kwrd { color: #0000ff; } .csharpcode .str { color: #006080; } .csharpcode .op { color: #0000c0; } .csharpcode .preproc { color: #cc6633; } .csharpcode .asp { background-color: #ffff00; } .csharpcode .html { color: #800000; } .csharpcode .attr { color: #ff0000; } .csharpcode .alt { background-color: #f4f4f4; width: 100%; margin: 0em; } .csharpcode .lnum { color: #606060; }

Textbox eingaben auf Zahlen beschränken

Eigentlich ist das Grundproblem immer das Gleiche. Benutzereingaben müssen überprüft werden. Nun ist leider in WinRT XAML die InputValidation und damit auch Regular Expression als Prüfmöglichkeit aktuell nicht vorhanden. Also muss man auf die guten alten Tastatureingaben zurückgreifen. Das passende Event der Textbox ist KeyDown. Folgender Code reduziert die Eingaben rein auf Zahlen (Alphanumerisch). Für alle unerwünschten Tastatur Ereignisse wird die Behandlung abgebrochen. Private Sub TextBox_KeyDown_1(sender As Object, e As KeyEventArgs) If e.Key >= Windows.System.VirtualKey.Number0 And e.Key <= Windows.System.VirtualKey.Number9 Then Else e.Handled = True End If .csharpcode, .csharpcode pre { font-size: small; color: black; font-family: consolas, "Courier New", courier, monospace; background-color: #ffffff; /*white-space: pre;*/ } .csharpcode pre { margin: 0em; } .csharpcode .rem { color: #008000; } .csharpcode .kwrd { color: #0000ff; } .csharpcode .str { color: #006080; } .csharpcode .op { color: #0000c0; } .csharpcode .preproc { color: #cc6633; } .csharpcode .asp { background-color: #ffff00; } .csharpcode .html { color: #800000; } .csharpcode .attr { color: #ff0000; } .csharpcode .alt { background-color: #f4f4f4; width: 100%; margin: 0em; } .csharpcode .lnum { color: #606060; } Windows 8 arbeitet nicht mit Keycodes, sondern Virtual Keys. Die Sondertasten werden über die Eventargs z.B. e.Key.RightShift abgefragt. Etwas schwieriger geht das mit ALT und STRG. ALT kann man meines Wissens nach gar nicht abfangen. Für die STRG Taste muss  man einen kleinen Umweg nehmen. Dim ctrl = Window.Current.CoreWindow.GetKeyState(VirtualKey.Control) If ctrl = Windows.UI.Core.CoreVirtualKeyStates.Down Then End If .csharpcode, .csharpcode pre { font-size: small; color: black; font-family: consolas, "Courier New", courier, monospace; background-color: #ffffff; /*white-space: pre;*/ } .csharpcode pre { margin: 0em; } .csharpcode .rem { color: #008000; } .csharpcode .kwrd { color: #0000ff; } .csharpcode .str { color: #006080; } .csharpcode .op { color: #0000c0; } .csharpcode .preproc { color: #cc6633; } .csharpcode .asp { background-color: #ffff00; } .csharpcode .html { color: #800000; } .csharpcode .attr { color: #ff0000; } .csharpcode .alt { background-color: #f4f4f4; width: 100%; margin: 0em; } .csharpcode .lnum { color: #606060; }

ListView 1x1

Bisher hat man bei einfachen Auswahllisten meist eine Listbox verwendet. Mit Windows 8 kommt nun ein sehr ähnlich klingendes Steuerelement hinzu: Listview. Listbox Listview Ohne das ich dazu Details in der Dokumentation von WinRT finde konnte, gehe ich davon aus, das Listbox das ältere einfachere Control ist. Listview sieht optisch ansprechender aus, unterstützt Gruppierung und Drag&Drop und reagiert moderner auf Touch. Überraschend zeigt der Task Manager weniger Speicherverbrauch bei Listview an. Dummy Daten Für die weiteren Tests wird eine Liste von Personen angelegt. Public Class person Private _name As String Public Property name() As String Get Return _name End Get Set(ByVal value As String) _name = value End Set End Property Private _alter As Integer Public Property alter() As Integer Get Return _alter End Get Set(ByVal value As Integer) _alter = value End Set End Property End Class .csharpcode, .csharpcode pre { font-size: small; color: black; font-family: consolas, "Courier New", courier, monospace; background-color: #ffffff; /*white-space: pre;*/ } .csharpcode pre { margin: 0em; } .csharpcode .rem { color: #008000; } .csharpcode .kwrd { color: #0000ff; } .csharpcode .str { color: #006080; } .csharpcode .op { color: #0000c0; } .csharpcode .preproc { color: #cc6633; } .csharpcode .asp { background-color: #ffff00; } .csharpcode .html { color: #800000; } .csharpcode .attr { color: #ff0000; } .csharpcode .alt { background-color: #f4f4f4; width: 100%; margin: 0em; } .csharpcode .lnum { color: #606060; } Public Class personen Inherits List(Of person) Public Sub New() Add(New person With {.name = "Hannes", .alter = 27}) Add(New person With {.name = "Monique", .alter = 34}) Add(New person With {.name = "Franz", .alter = 62}) Add(New person With {.name = "kevin", .alter = 12}) Add(New person With {.name = "Albert", .alter = 43}) Add(New person With {.name = "Scott", .alter = 38}) Add(New person With {.name = "Michael", .alter = 89}) Add(New person With {.name = "Sabine", .alter = 22}) Add(New person With {.name = "Fiona", .alter = 14}) Add(New person With {.name = "Zora", .alter = 50}) Add(New person With {.name = "Vanessa", .alter = 23}) End Sub End Class .csharpcode, .csharpcode pre { font-size: small; color: black; font-family: consolas, "Courier New", courier, monospace; background-color: #ffffff; /*white-space: pre;*/ } .csharpcode pre { margin: 0em; } .csharpcode .rem { color: #008000; } .csharpcode .kwrd { color: #0000ff; } .csharpcode .str { color: #006080; } .csharpcode .op { color: #0000c0; } .csharpcode .preproc { color: #cc6633; } .csharpcode .asp { background-color: #ffff00; } .csharpcode .html { color: #800000; } .csharpcode .attr { color: #ff0000; } .csharpcode .alt { background-color: #f4f4f4; width: 100%; margin: 0em; } .csharpcode .lnum { color: #606060; } Im XAML Code ist ein  Button zum löschen von Einträgen deklariert. Die Zuweisung der Liste erfolgt über das Attribut Itemssource. Da das Listview Control nicht weis, was es genau anzeigen soll, muss man entweder ins Datatemplate gehen oder das Attribut DisplayMemberpath setzen, ganz wie in Silverlight. <ListView Width="200" HorizontalAlignment="Left" AllowDrop="True" SelectionMode="Single" DisplayMemberPath="name" Height="350" Margin="39,10,46,-60" Name="listbox1"/> <Button Content="Button" HorizontalAlignment="Right" Width="75" Click="Button_Click_1"/> .csharpcode, .csharpcode pre { font-size: small; color: black; font-family: consolas, "Courier New", courier, monospace; background-color: #ffffff; /*white-space: pre;*/ } .csharpcode pre { margin: 0em; } .csharpcode .rem { color: #008000; } .csharpcode .kwrd { color: #0000ff; } .csharpcode .str { color: #006080; } .csharpcode .op { color: #0000c0; } .csharpcode .preproc { color: #cc6633; } .csharpcode .asp { background-color: #ffff00; } .csharpcode .html { color: #800000; } .csharpcode .attr { color: #ff0000; } .csharpcode .alt { background-color: #f4f4f4; width: 100%; margin: 0em; } .csharpcode .lnum { color: #606060; } Um nun die Bindung zwischen Control und Objekt auch in beide Richtungen aktiv werden zu lassen, reicht es nicht mit der generischen Liste zu arbeiten. Wir brauchen ein Notification System->ObservableCollection. Anders wie in .NET ist das kein echter Datentyp in WinRT sondern wird gewrapped auf IObservableVector. Weswegen auch nur in VB und C# der aus Silverlight bekannte Weg zur Verfügung steht. Sie können aus den NET Sprachen auch direkt mit dem WinRT Typen arbeiten. Meist wird man das nicht tun um vorhandenen Code nutzen zu können. Also folgender Code macht die gebundene Liste Observable Dim p As New ObservableCollection(Of person)(New personen) Private Sub UserControl2_Loaded(sender As Object, e As RoutedEventArgs) Handles Me.Loaded listbox1.ItemsSource = p End Sub Private Sub Button_Click_1(sender As Object, e As RoutedEventArgs) p.RemoveAt(listbox1.SelectedIndex) End Sub .csharpcode, .csharpcode pre { font-size: small; color: black; font-family: consolas, "Courier New", courier, monospace; background-color: #ffffff; /*white-space: pre;*/ } .csharpcode pre { margin: 0em; } .csharpcode .rem { color: #008000; } .csharpcode .kwrd { color: #0000ff; } .csharpcode .str { color: #006080; } .csharpcode .op { color: #0000c0; } .csharpcode .preproc { color: #cc6633; } .csharpcode .asp { background-color: #ffff00; } .csharpcode .html { color: #800000; } .csharpcode .attr { color: #ff0000; } .csharpcode .alt { background-color: #f4f4f4; width: 100%; margin: 0em; } .csharpcode .lnum { color: #606060; }Jedes Mal wenn Benutzer auf Button clickt, verschwindet das ausgewählte Element mit einer Animation aus der Liste.

TextBox neu kennenlernen

Windows 8  stellt XAML wieder auf zurueck auf Start. Vieles was man aus WPF oder Silverlight neuester Generation gewohnt ist, funktioniert ploetzlich nicht mehr oder anders. So z.B. die Textbox und RichEditBox. Eine Textbox ist wie jedes andere native WinRT Control Touch orientiert. Wenn der Benutzer in diese tapped (mit Finger berührt) erscheint das virtuelle Keyboard. Im Bild sehen wir den Screenshot des Simulators mit Englischen Language Settings. Wenn die Textbox von der virtuellen Tastatur verdeckt wird, schiebt Windows die Anwendung nach oben, so dass die der Benutzer den Dialog nutzen kann. Die Tastatur kann man (wie bei Windows Phone) ändern über das Attribut InputScope. <TextBox.InputScope> <InputScope> <InputScope.Names> <InputScopeName NameValue="TelephoneNumber"/> </InputScope.Names> </InputScope> </TextBox.InputScope> .csharpcode, .csharpcode pre { font-size: small; color: black; font-family: consolas, "Courier New", courier, monospace; background-color: #ffffff; /*white-space: pre;*/ } .csharpcode pre { margin: 0em; } .csharpcode .rem { color: #008000; } .csharpcode .kwrd { color: #0000ff; } .csharpcode .str { color: #006080; } .csharpcode .op { color: #0000c0; } .csharpcode .preproc { color: #cc6633; } .csharpcode .asp { background-color: #ffff00; } .csharpcode .html { color: #800000; } .csharpcode .attr { color: #ff0000; } .csharpcode .alt { background-color: #f4f4f4; width: 100%; margin: 0em; } .csharpcode .lnum { color: #606060; } Mögliche Werte sind Url EmailSmtpAddress Number TelephoneNumber Search AlphanumericHalfWidth (ohne erkennbaren Effekt) Man kann auch das Attribut verwenden und in dem Fall den default Wert zuweisen. <TextBox Width="200" HorizontalAlignment="Left" InputScope="Default"/> .csharpcode, .csharpcode pre { font-size: small; color: black; font-family: consolas, "Courier New", courier, monospace; background-color: #ffffff; /*white-space: pre;*/ } .csharpcode pre { margin: 0em; } .csharpcode .rem { color: #008000; } .csharpcode .kwrd { color: #0000ff; } .csharpcode .str { color: #006080; } .csharpcode .op { color: #0000c0; } .csharpcode .preproc { color: #cc6633; } .csharpcode .asp { background-color: #ffff00; } .csharpcode .html { color: #800000; } .csharpcode .attr { color: #ff0000; } .csharpcode .alt { background-color: #f4f4f4; width: 100%; margin: 0em; } .csharpcode .lnum { color: #606060; } Mit Visual Studio 2012 RC und Windows 8 PC sieht Number so aus. Eine Möglichkeit per Regular Expressions die Eingabe einzuschränken ist in WinRT nicht vorhanden.