Sunday, January 30, 2011

Jesse Jane Best Movie?

TFS 2010 object model: recovery projects

In the previous post (link , link ) we saw how to use the TFS 2010 object model to connect to a TFS server and recover the project collection therein.

Niche In this post we will see ways to retrieve the properties of these projects within the project collections.

Query on server nodes

The first way is to use a mechanism similar to that seen in the previous post for the recovery of the collections based on the use of the method QueryChildren property CatalogNode:

  1. Dim tfs = TfsConfigurationServerFactory . GetConfigurationServer ( New Uri ( "http://server:8080/tfs" )
  2.                                                                 New UICredentialsProvider ())
  3. Dim allProjects = tfs.CatalogNode.QueryChildren({ CatalogResourceTypes .TeamProject},
  4.                                            True ,
  5.                                            CatalogQueryOptions .IncludeParents)

In questo caso otteniamo una collezione in sola lettura di CatalogNode nella cui proprietà Resource sono presenti le proprietà del progetto (nome, descrizione, etc., etc.).
Poichè abbiamo utilizzato l’opzione IncludeParents, otteniamo che, per ogni catalogNode, la proprietà Parent contiene il nodo relativo alla collection di appartenenza.
Il parametro recurse=true nella precedente query è fondamentale in quanto i progetti non sono direttamente contenuti nel server.
Se mettiamo recurse=false otteniamo una collezione vuota.

Se volessimo ottenere i progetti contenuti in una specific collection, we could use a LINQ query like this:

  1. Dim tfs = TfsConfigurationServerFactory . GetConfigurationServer ( New Uri ( "http://server:8080/tfs" ) ,
  2. , & # 160; , & # 160; ; New UICredentialsProvider ())
  3. Dim allProjects = tfs.CatalogNode.QueryChildren({ CatalogResourceTypes .TeamProject},
  4.                                            True ,
  5.                                            catalog query options . Include parents)
  6. Dim collProjects = From n In allProjects . OfType ( Of CatalogNode ) ()
  7. & # 160; ; Where = n.ParentNode.Resource.DisplayName "DomusDotNet"
  8.                      Select n

Query sui nodi della Project Collection

Un altro modo per ottenere i progetti presenti all’interno di una collection è quello di eseguire una query sui nodi contenenti le risorse direttamente su un’istanza di TfsTeamProjectCollectionNel precedente post della serie, abbiamo visto i tre modi possibili per TfsTeamProjectCollection get an instance of the class. Suppose, then to have one and want to retrieve the properties of the projects in it:

  1. Dim collProjects tfsColl1.CatalogNode.QueryChildren = ({ CatalogResourceTypes . TeamProject},
  2. & # 160; , & # 160; , & # 160; False ,
  3.                                                          CatalogQueryOptions .None)

In questo caso non serve la recursione e il recupero dei nodi padre perchè i progetti sono gerarchicamente disposti sotto la collection.

 

Tuesday, January 25, 2011

Strep Throat Symptoms And Teethache

Event Online Application Development with VB.NET by WP7 WPF Tips & Tricks

I must point out that the online event will be held on January 27 at 21:00. Speakers of the event will

Alessandro Del Sole and Renato Marzaro both MVP for Visual Basic, and a guarantee of quality.

For more info and registration at the event, refer to:

http://www.wpfitalia.it/Eventionline.aspx

Sunday, January 23, 2011

Bunsoy Kasi Translation

TFS 2010 object model: retrieve information from the project collections

In this post I will show how to recover and the information contained in the collection of Project Team Foundation Server using the Object Model messoci SDK available.

In the previous post

series we have seen how to connect to the TFS server, and then we take for granted being able to access the server.

To retrieve the collections of the project we can use the property CatalogNode TfsConfigurationServer class and perform a query to obtain the nodes of type Collection:

  1. Dim tfsInstance = TfsConfigurationServerFactory . GetConfigurationServer ( New Uri ( "http://server:8080/tfs" )) Dim
  2. tfsInstance.CatalogNode.QueryChildren collections = ({ CatalogResourceTypes . ProjectCollection} &
  3. # 160; ; & # 160; ; False , CatalogQueryOptions . None)

The variable collections contain a collection of read-only CatalogNode which are contained in the data we wanted. In particular

CatalogNode has a property of type Resource CatalogResource.

The most important properties of the class are CatalogeResource:

  • Description: description of the collection (generally the resource). It is the description that we have entered during creation of the collection;
  • DisplayName : name of the collective. It 's the name we included in the collection creation wizard;
  • Identifier: This is a GUID that uniquely identifies the resource-level catalog;
  • Properties: it is an object that implements IDictionary (Of String, String) in which contained property of the node. In particular, in this dictionary are the property instanceId useful when we want to retrieve the reference to the services exposed by the collection;
  • ResourceType : contains the type of the resource. In this case it is TeamprojectCollection.

property CatalogNode a TfsConnection allows to obtain all the information relative ai nodi apparteneti alla connessione. Nel caso della TfsConfigurationServer si tratta di tuti gli oggetti contenuti nel server tra cui collection, progetti e via discorrendo.

Possiamo recuperare le informazioni contenute nella CatalogeNode anche avendo a disposizione l’istanza della Project Collection (cioè un’istannza della classe TfsTeamProjectCollection).

Prima di vedere come recuperare le informazioni di cui sopra vediamo come è possibile ottenere l’istanza della TFSTeamProjectCollection.

Se abbiamo a disposizione un’istanza della TfsConfigurationServer (vedi il post precedente), possiamo utilizzare il metodo GetTeamProjectCollection.

The method provides, as an argument, the instance identifier of the collection you want to retrieve. This is a GUID that is recoverable in the Properties property of the collection CatalogeResource instance with key "instanceId"

  1. Dim tfs = TfsConfigurationServerFactory . GetConfigurationServer ( New Uri ( "http://server:8080/tfs" )
  2. , & # 160; , & # 160; ; New UICredentialsProvider ())
  3. Dim collections = tfs.CatalogNode.QueryChildren({ CatalogResourceTypes .ProjectCollection},
  4.                                                               False ,
  5.                                                               CatalogQueryOptions . None)
  6. Dim collInstanceId = (n From In collections
  7. & # 160; Where n.Resource.DisplayName = "name collection"
  8. & # 160; Select n.Resource.Properties( "InstanceId" )).FirstOrDefault()

E’ evidente che se non abbiamo l’instance identifier e dobbiamo recuperarlo con il precedente pezzo di codice, abbiamo anche tutte le informazioni culla collection senza dover utilizzare l’istanza di TfsTeamProjectCollection ottenuta con il metodo GetTeamProjectCollection.

Supponiamo, per un attimo, di avere l’instace id senza dover accedere ai nodi della CatalogeNode dell’istanza di TfsConfigurationServer. In questo caso, per ottenere l’istanza di TfsTeamProjectCollection è sufficiente:

  1. Dim tfs = TfsConfigurationServerFactory . GetConfigurationServer ( New Type ( "http://server:8080/tfs" ),
  2. : & # 160; : & # 160; ; New UICredentialsProvider ()) Dim
  3. tfsColl = tfs . GetTeamProjectCollection ( New Guid (collInstanceId))

where instanceId is the string that identifies the instance of the Id collection.

GetTeamProjectCollection method behaves similarly to what we saw in the previous TfsConfigurationServerFactory post :

  • if the instance of TfsConfigurationServer on which usage was generated by TfsConfigurationServerFactory, then the instance returned from the method will always same;
  • if the instance of TfsConfigurationServer on which usage has been instantiated using the constructor, then the instance returned from the method will be different for each call.

Two other ways to retrieve the instance of TfsTeamProjectCollection are

  • use the constructor of the class TfsTeamProjectCollection:
  1. Dim tfsColl = New TfsTeamProjectCollection ( New Uri ( "http://server:8080/tfs/nomecollection" )
  2. & # 160; , & # 160; New UICredentialsProvider ())
  • use the factory class TfsTeamProjectCollectionFatctory:
  1. Dim tfsColl = TfsTeamProjectCollectionFactory . GetTeamProjectCollection ( New Uri ( " http://server:8080/tfs/nomecollection ")
  2. & # 160; , & # 160; , & # 160; ; New UICredentialsProvider ())

We observe that the URL of the collection is obtained by concatenating the name of the server URL colection.

If we use the factory, we will get the same instance of TfsTeamProjectCollection, while the manufacturer allows us to have a different instance each time.

When we have the instance to access the server component of the project collection, the same information can be recovered by going directly to the property and in particular to the property CatalogNode Resource:

  1. Dim collName = tfsColl.CatalogNode.Resource.DisplayName
  2. Dim collDescription = tfsColl.CatalogNode.Resource.Description
  3. Dim collInstanceId tfsColl.CatalogNode.Resource.Properties = ( "InstancreId" )

Another way to retrieve information relating to the collection in our server is to require TfsConfigurationServer instance, the service ITeamProjectCollectionService through education:

  1. Dim tfs = TfsConfigurationServerFactory . GetConfigurationServer ( New Type ( "http://rma-mbnb01-dev:8080/tfs" )
  2. & # 160; & # 160; & # 160; New UICredentialsProvider ()) Dim
  3. temProSrv = CType ( tfs . GetService ( Of ITeamProjectCollectionService ) (), ITeamProjectCollectionService )

and then invoke the method GetCollections:

  1. Dim collections = temProSrv . GetCollections ()

The result of this is a IList (Of TeamProjectCollection). The TeamProjectCollection is a class in this namespace Microsoft.TeamFoundation.Framework.Client and contains information relating to the collection project and a bit more.

Friday, January 21, 2011

What Are The Four Stages Lupus

But when a simple, boring !! Contracts on ioProgrammo

E 'a while that I post to "vent" and it's time to make a!

Today I happened to read some comments related to WP7, which said that the operating system has not found favor with the public because they are too simple to be boring!

Since the ease of use means that a product does not meet public favor ?!?!?!?!

We complained about why Windows Mobile complex, slow, cumbersome, etc.. Etc.. and now this is too easy to use ?!?!?!

I have given up the phone to my wife who does not love the technology and using a telephone in which the maximum dell'avveniristico is the MMS and was able to use it without an engineering degree Nuclear! It has not even filed for divorce because they are bought me!!

If WP7 did not find the expected success is not due to the fact that it is simple to use! The fact that the interface is minimal can be worn as a downside: can like it or not, but it is a negative side!

That said, personally I enjoy like a hedgehog to read the mail with a few taps of your finger, you think of it as you like!

What Is Cervical Mucous Like After Conception

Code of February 2010

E 'output in the February issue of ioProgrammo , an introduction to my article on the Contracts Code.

4-159g

Technorati tags: code contracts, ,

Saturday, January 15, 2011

Decorative Beads To Buy In Bulk

TFS Object Model: a server to connect to TFS

Because of the work I am busy lately to interact, via code, using the object model, with TFS . I would like to start a mini series dedicated to tips and short articles on the use of certain classes in the same object model. The series is not meant to be exhaustive but is intended as my habit of sharing know-how.

This post covers the initial part of every interaction with TFS: The connection to the server.

If we want to create client applications that interact with Team Foundation Server 2010, we can use the object model made available by libraries Microsoft.TeamFoundation .*. dll.

image

In particular to connect to the server you need to reference libraries and Microsoft.TeamFoundation.Client.dll Microsoft.TeamFoundation.Common.dll.

The connection to the TFS server (in order to obtain services for the management of the entity's own server) can be done using the class contained within the namespace TFSConfigurationServer Microsoft.TeamFoundation.Client (Microsoft.TeamFoundation.Client assembly. dll).

E 'can create an instance of TFSConfigurationServer in two ways: Using the manufacturer

  • :
  1. Dim tfsInstance1 = New TfsConfigurationServer ( New Uri ( "http://server:8080/tfs" ) New UICredentialsProvider ())
  • Using the factory class TFSConfigurationServerFactory:
  1. Dim tfsInstance1 = TfsConfigurationServerFactory . GetConfigurationServer ( New Uri ( "http://server:8080/tfs" ) New UICredentialsProvider ())

In both cases the address http://server:8080 / tfs must be a valid address to connect to TFS. We can get the address using the Team Explorer. And 'Just open the properties of a collection of Team Explorer to get the address to be included in our classrooms:

image

Both manufacturer who make available factory overload to specify the login credentials, but at this time, non ce ne preoccupiamo e come provider di credenziali utilizziamo la classe UICredentialProvider che permette, se TfsConfigurationServer non trova delle credenziali in cache, di richiederle all’utente con un prompt.

Quello che ci interessa in questo post è mettere in evidenza la sostanziale differenza tra costruttore e factory e cioè il fatto che il costruttore permette di ottenere differenti istanze di conessione  (una per ogni New) mentre la factory crea una nuova istanza la prima volta che viene richiamato il metodo GetConfigurationServer e restituisce la stessa istanza le volte successive.

Per verificare questo non possimao utilizzare il metodo Equals delal classe Object perchè tale metodo e ridefinito in the class from which the TfsConnection TfsConfigurationServer comes to compare two instances of the class defined as equal when they have the same URL. Then write the following code:

  1. Dim tfsInstance1 = New TfsConfigurationServer ( New Uri ( "http://server:8080/tfs" )
  2. & # 160; , & # 160; ; New UICredentialsProvider ()) Dim
  3. tfsInstance2 = New TfsConfigurationServer ( New Type ( "http://server:8080/tfs" )
  4. & # 160; & # 160; New UICredentialsProvider ())
  5. tfsInstance1 . Dispose ()

Following the call to the Dispose method, if the instances are distinct, tfsInstance1 will be "provisions" while tfsInstance2 not.

To test this we insert the QuickWatch in our project to highlight the Disposed property values \u200b\u200b(which are not directly visible because Friend) and we observe that, after Dispose has:

image

Let the same thing for the instances generated by the Factory:

    Dim
  1. tfsInstance1 = TfsConfigurationServerFactory . GetConfigurationServer ( New Type ( "http://server:8080/tfs" )
  2. &
  3. # 160; : & # 160; : & # 160; ; New UICredentialsProvider ())
  4. Dim tfsInstance2 = TfsConfigurationServerFactory .GetConfigurationServer( New Uri ( "http://server:8080/tfs" ),
  5.                                                                      New UICredentialsProvider ())
  6. tfsInstance1 . Dispose ()

In this case, tell us QuickWatch:

image

If this were not enough, we can analyze GetConfigeurationServer is implemented as the method of using TfsConfigurationServerFactory Reflector :

image

The class implements a sort of cache (this is a Dictionary (Of Uri, TfsConfigurationServer)) in which it is sought any instance already created ( Step 1) and, in this case it is returned. If there is an instance for the URI passed as an argument, the factory uses the constructor to instantiate a new TfsConfigurationServer and stores in its cache (step 2).

Tuesday, January 11, 2011

Split Entry Remodel Blog

Sample Code

The Visual Basic team, adhering to the requests made by the developer community VB.NET (Which, in spite of the C-sharpisti is large and vital Sorriso), published a series of examples ranging from 7 to Phone Windows Azure.

You can find the complete list at this link .

also found on the pages indicated wishlist VB code, or the ability to tell the VB team to an article or a snippet of code that you want to appear in the examples.

Technorati Tags: vb.net , , example, snippet, code

Sunday, January 9, 2011

Wedding Reception Program Outline

VB.NET VB for Dummies: The Serialization - Part 2

This post is a continuation of previous post serialization.

In particular we will see that the SOAP and JSON serialization.

Serialization SOAP SOAP serialization is committed to the SoapFormatter System.Runtime.Serialization.Formatters.Soap contained in the namespace in the library of the same name. The SOAP formatter

goes back to the earliest versions of the framework and, unfortunately, from a certain point, even though it was declared obsolete, it was not brought forward in the development and does not support certain types of data very much used in the world. NET such as generics and nullable.

For this reason, we can not serialize in SOAP format (using the SoapFormatter) our bill (see previous post) as this has a property of type List (Of DettagliFattura) (generic).

JSON serialization format JSON serialization (more info here ) is a textual format very popular in AJAX applications. Entry is a way to serialize complex objects even with a very compact size and easy to interoperate with JavaScript, therefore, well suited for scenarios partoicolarmente AJAX-style web.

JSON serialization can be done using the class DataContractJsonSerializer that framework 4.0 is contained in the namespace System.Runtime.Serialization.Json all’interno dell’omonimo assembly.

Fate attenzione perchè, se state sviluppando per il framework 3.5 (prima di questo la classe DataContractJsonSerialization non era presente), trovate la classe nello stesso namespace ma l’assembly è System.ServiceModel.Web.

La classe DataContractJsonSerializer prevede, tra i vari metodi, WriteObject e ReadObject che permettono , rispettivamente, di serializzare e deserializzare un’oggetto in formato JSON.

Entrambi i metodi sfruttano uno stream per serializzare l’oggetto. In base alle nostre esigenze tale stream potrebbe essere in memoria (come nell’esempio riportato in seguito), su file o su un canale web (ad esempio come response to a request from a remote client).

methods for serialization and deserialization of the object are Invoice:

  1. Public Shared Function SerializzaJSON (ByVal bill As Invoice ) As String
  2. If bill Is Nothing Then Throw New ArgumentNullException ( "Bill" )
  3.      Dim strJSON As String = Nothing
  4.      Dim serializer = New DataContractJsonSerializer ( GetType ( Fattura ))
  5.      Using memStream = New MemoryStream ()
  6.          serializer .WriteObject(memStream, fattura)
  7.         strJSON = Encoding.Default.GetString( memStream .ToArray())
  8.      End Using
  9.      Return strJSON
  10. End Function
  11.  
  12. Public Shared Function DeserializzaJSON( ByVal As strFattura String) As Invoice
  13. Dim retObj As Invoice = Nothing
  14. & # 160; Dim serializer = New DataContractJsonSerializer ( GetType ( Invoice )) &
  15. # 160; Using memStream = New MemoryStream (Encoding.Default.GetBytes (strFattura))
  16. retObj = CType (serializer . ReadObject (memStream) Invoice )
  17. End Using Return
  18. retObj
  19. End Function

The result is as follows:

image

We observe that, in the examples, we used the default encoding for strings. Evidently, if necessary, the encoding may be the one we want.

If our class (as in Bill) is composed of objects. NET serializable, we can immediately use the JSON serialization.

Alternatively, we can decorate our class (and all those that may be used as a property) with the Serializable attribute or the attribute DataContract.

In the first case it is enough to decorate the sun and JSON serialization classes will have the properties expressed by the name of the attribute that is encapsulated by private property. In the case of property definite in modo compatto (come accade nella Fattura) il compilatore crea, dietro le quinte un attributo per ogni proprietà con lo stesso nome della proprietà a cui viene anteposto il carattere “_”. In questo caso il JSON risultante vedrà le proprietà espresse con il nome della proprietà preceduta da “_”.

Nel caso dell’attributo DataContract, invece, è necessario decorare anche ogni proprietà con l’attributo DataMember (se una proprietà non viene decorata con DataMember, questa non finisce nella serializzazione).

L’attributo DataMember permette di rinominare la proprietà all’interno del JSON risultante:

  1. \u0026lt; DataMember (Name: = "numeroDocumento" )>
  2. Public Property NumeroDocumento As String

In this case, the properties, the ' inside of the JSON, will be called "numeroDocumento" and not "NumeroDocumento.

using DataContract and DataMember we can intervene in the resulting JSON in order to customize the results to our liking (especially useful when we are given the path and we must re-create the class).

Serializzazion custom

Just a hint at the possibility of creating a custom serialization of objects.

To do this, the framework provides us with the interface that has two IFormatter Serialize and Deserialize methods that we have to redefine our logic by implementing the serialization / deserialization:

An example might be:

  1. Imports System.Runtime.Serialization
  2. Public Class MioSerializzatore
  3. Implements IFormatter
  4.  
  5.      Public Property Binder As System.Runtime.Serialization. SerializationBinder Implements System.Runtime.Serialization. IFormatter .Binder
  6.          Get
  7.  
  8.          End Get
  9.          Set ( ByVal value As System.Runtime.Serialization. SerializationBinder )
  10.  
  11.          End Set
  12.      End Property
  13.  
  14.      Public Property Context As System.Runtime.Serialization. StreamingContext Implements System.Runtime.Serialization. IFormatter .Context
  15.          Get
  16.  
  17.          End Get
  18.          Set ( ByVal value As System.Runtime.Serialization. StreamingContext )
  19.  
  20.          End Set
  21.      End Property
  22.  
  23.      Public Function Deserialize( ByVal serializationStream As System.IO. Stream ) As Object Implements System.Runtime.Serialization. IFormatter . Deserialize
  24. 'Here comes the logic of deserialization
  25. End Function
  26. Public Sub Serialize (ByVal serializationStream As System.IO. Stream , ByVal graph As Object ) Implements System.Runtime.Serialization. IFormatter .Serialize
  27.          ' qui ci va la logica di serializzazione
  28.      End Sub
  29.  
  30.      Public Property SurrogateSelector As System.Runtime.Serialization. ISurrogateSelector Implements System.Runtime.Serialization. IFormatter .SurrogateSelector
  31.          Get
  32.  
  33.          End Get
  34.          Set ( ByVal value As System.Runtime.Serialization. ISurrogateSelector )
  35. End September
  36. End Property End
  37. Class
Technorati tags: serialization, serialization , , xml, soap , ,

Saturday, January 8, 2011

Wrestling Singlets For Baby

WP7 Tip: Changing the background of a control based on the theme

Following a thread appeared on forum for the development in Microsoft Windows phone I will return an implementation of a converter that allows you to change the background of a control in XAML based on the active theme.

Getting Started "steal" the tip of the evil genius on the way to determine the active theme (link ) and convert it to VB.NET. In particular, we create a shared method (but should be a property shared well) in our application class App:

  1. Public Shared Function GetCurrentTheme() As Theme
  2.      Dim bgc = App.Current.Resources( "PhoneBackgroundColor" ).ToString()
  3.      If bgc = "#FF000000" Then
  4.          Return Theme .Dark
  5. Else
  6. Return Theme .
  7. Light
  8. End If End
  9. Function

Theme enumeration is defined as follows:

  1. Public Enum Theme
  2. Dark
  3. Light
  4. End Enum

At this point we can create our conveter:

  1. Imports System.Windows.Data
  2. Imports System.Windows.Media
  3. Public Class ThemeColorConverter
  4. Implements IValueConverter
  5. Private Function GetColorFromName( ByVal strColor As String ) As Color ?
  6.          Dim retColor As Color ? = Nothing
  7.          Try
  8.              Dim propColor = GetType ( Colors ).GetProperty(strColor)
  9.              If propColor IsNot Nothing Then
  10.                  Dim value = propColor .GetValue( Nothing , Nothing )
  11.                  If value IsNot Nothing Then
  12.                     retColor = CType (value, Color )
  13.                  End If
  14.              End If
  15.          Catch ex As Exception
  16.             retColor = Nothing
  17.          End Try
  18.          Return retColor
  19.      End Function
  20.  
  21.      Private Function GetColorFromRGB( ByVal strColor As String ) As Color ?
  22.          Dim retColor As Color ? = Nothing
  23.         strColor = strColor .Replace( "#" , "" )
  24.          Dim a As Byte = 255
  25.          Dim r As Byte = 255
  26.          Dim g As Byte = 255
  27.          Dim b As Byte = 255
  28.          Dim start = 0
  29.          If strColor .Length = 6 Or strColor .Length = 8 Then
  30.              If strColor .Length = 8 Then
  31.                 a = Byte .Parse( strColor .Substring(0, 2), System.Globalization. NumberStyles .HexNumber)
  32.                 start = 2
  33.              End If
  34.             r = Byte .Parse( strColor .Substring(start, 2), System.Globalization. NumberStyles .HexNumber)
  35.             g Bytes = . Parse ( strColor . Substring (start + 2, 2), System.Globalization. NumberStyles . HexNumber)
  36. & # 160; b = Byte . Parse ( strColor . Substring (start + 4, 2) , System.Globalization. NumberStyles . HexNumber)
  37. & # 160; retColor = Color .FromArgb(a, r, g, b)
  38.          End If
  39.          Return retColor
  40.      End Function
  41.  
  42.      Private Function GetColor( ByVal strColor As String ) As Color
  43.          Dim retColor As Color
  44.  
  45.          Dim tmpColor = GetColorFromName(strColor)
  46.          If Not tmpColor .HasValue Then
  47.             tmpColor = GetColorFromRGB(strColor)
  48.              If tmpColor .HasValue Then
  49.                 retColor = tmpColor .Value
  50.              End If
  51.          Else
  52.             retColor = tmpColor .Value
  53.          End If
  54.  
  55.          Return retColor
  56.      End Function
  57.  
  58.      Public Function Convert( ByVal value As Object ,
  59.                              ByVal targetType As System. Type ,
  60.                              ByVal parameter As Object ,
  61.                              ByVal culture As System.Globalization. CultureInfo ) As Object Implements System.Windows.Data. IValueConverter .Convert
  62.          If value IsNot Nothing Then
  63.              Dim brush As SolidColorBrush = Nothing
  64. ,.. Dim values \u200b\u200b= value ToString () Split ( " If
  65. App .GetCurrentTheme() = Theme .Light Then
  66.                     brush = New SolidColorBrush (GetColor(values(0)))                  Else
  67.                     brush = New SolidColorBrush
  68. (GetColor(values(1)))
  69.                  End
  70. If              End
  71. If              Return
  72. brush
  73.          Else
  74.             
  75. Return Nothing
  76.          End
  77. If      End
  78. Function  
  79.     
  80. Public Function ConvertBack( ByVal
  81. value
  82. As
  83. Object ,                                  ByVal targetType As System. Type ,
  84.                                 
  85. ByVal parameter As Object ,
  86.                                 
  87. ByVal culture As System.Globalization. CultureInfo ) As
  88. Object Implements System.Windows.Data. IValueConverter .ConvertBack          Throw New NotImplementedException ()
  89.     
  90. End Function End
  91. Class
  92. La funzione GetColor ci consente di obtain a Color object from a string in the following formats AARRGGBB #, # RRGGBB or "color name" (as that may be one of the possible colors of the class Colors ).
  93. The Convert method of our converter retrieves the argument value, which by convention should be a string with the following format:
light color theme can be used directly in binding within the XAML.

To do this you simply reference the appropriate namespace:

xmlns:

my = "clr-namespace: WP7ThemeBackground"

    Insert the converter into the resources of 'application or page
  1. \u0026lt; phone
:
PhoneApplicationPage.Resources

>

  1. \u0026lt; my : ThemeColorConverter x :
  2. Key = "TCC"> \u0026lt;/ my : ThemeColorConverter > \u0026lt;/ phone : PhoneApplicationPage.Resources >
  3. And finally, put the drive in with the background binding of control desired: \u0026lt; Grid
x
:

Name = "LayoutRoot"
  1. Background = "{Binding Converter = { StaticResource TCC} , Source = Red \u0026lt; phone : phone application page x
:
Class

= "WP7ThemeBackground.MainPage"

xmlns = "http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  1. ; xmlns: x = "http://schemas.microsoft.com/winfx/2006/xaml"
  2. xmlns: phone = "clr-namespace: Microsoft.Phone.Controls; Microsoft.Phone assembly ="
  3. ; xmlns:
  4. shell = "clr-namespace: Microsoft.Phone.Shell; Microsoft.Phone assembly =" & # 160; xmlns:
  5. d = "http://schemas.microsoft.com/expression/blend/2008"     xmlns :
  6. mc ="http://schemas.openxmlformats.org/markup-compatibility/2006"     xmlns :
  7. my ="clr-namespace:WP7ThemeBackground"     mc :
  8. Ignorable ="d" d : DesignWidth
  9. ="480" d : design height = "768"
  10. FontFamily = "{ StaticResource phone FontFamily normal} " font size = "{ StaticResource phone font size normal} "
  11. Foreground = "{ StaticResource PhoneForegroundBrush} "
  12.    
  13. SupportedOrientations ="Portrait" Orientation ="Portrait"     shell
  14. : SystemTray.IsVisible ="True" >      <
  15. phone : PhoneApplicationPage.Resources >
  16.         
  17. < my : ThemeColorConverter
  18. x : Key ="TCC"></ my : ThemeColorConverter
  19. >      </ phone : PhoneApplicationPage.Resources >      <!--LayoutRoot is the root grid where all page content is placed-->      <
  20. Grid x : Name ="LayoutRoot" Background ="{
  21. Binding Converter ={
  22. StaticResource TCC} , Source =Red AA00FF00} "> \u0026lt; Grid. RowDefinitions > & # 160; \u0026lt; RowDefinition Height = "Auto" />
  23. <
  24. RowDefinition Height ="*"/>         
  25. </ Grid.RowDefinitions >           
  26. <!--TitlePanel contains the name of the application and page title--> \u0026lt; StackPanel
  27. x
  28. : Name = "title panel" Grid.Row
  29. = "0"
  30. Margin
  31. = "12,17,0,28> & # 160;
  32. \u0026lt; TextBlock x : Name = "application title" text = "My Application" Style = "{ StaticResource
  33. phone text normal style}
  34. "/> & # 160; \u0026lt; TextBlock x : name = "page title" text = "pagename" Margin = "9, -7,0,0"
  35. Style = "{
  36. StaticResource PhoneTextTitle1Style } "/> \u0026lt;/ StackPanel > \u0026lt;- content panel - place additional content here -> \u0026lt; Grid
  37. x
  38. : Name = "content panel" Grid.Row
  39. = "1"
  40. Margin
  41. = "12,0,12,0"> \u0026lt;/
  42. Grid>
  43. \u0026lt;/ Grid> \u0026lt;/ phone: PhoneApplicationPage >
  44. Tag on Technorati: IValueConverter ,
  45. WP7
  46. , binding , phone windows 7 , background , solidbrush , color, colors