Windows Presentation Foundation contiene numerosi controlli volti a caricare informazioni e ad interagire con l'utente che rispecchiano nello stile e nelle funzionalità gli elementi Win32. La libertà è comunque massima così come la personalizzazione nell'interfaccia. Tipica è l'esigenza di una ComboBox che deve essere arricchita non limitandosi al semplice testo, ma mostrando anche immagini per ogni elemento.
L'uso di una ComboBox è piuttosto semplice, così come il suo popolamento mediante una collezione di ComboBoxItem:
ComboBox SelectedIndex="0">
ComboBoxItem> Yellow /ComboBoxItem>
ComboBoxItem> Green /ComboBoxItem>
/ComboBox>
Solitamente però, si utilizzano le funzionalità di binding per caricare automaticamente i dati, anche in formato XML:
Canvas>
Canvas.Resources>
XmlDataProvider x:Key="colors" XPath="/items/item">
x:XData>
items xmlns="">
item color="Red" />
item color="Yellow" />
item color="Blue" />
item color="Green" />
/items>
/x:XData>
/XmlDataProvider>
/Canvas.Resources>
ComboBox SelectedIndex="0" ItemsSource="{Binding Source={StaticResource colors}}"
DisplayMemberPath="@color" />
/Canvas>
Con la proprietà ItemsSource indichiamo qual è la sorgente da utilizzare, mentre con DisplayMemberPath specifichiamo qual è il path (in questo caso l'attributo) da mostrare come testo per ogni item. Possiamo però personalizzare e decidere in dettaglio l'aspetto di ogni item inserendo qualsiasi Visual presente in WPF: controlli, immagini e perfino video. Per fare ciò con la proprietà ItemTemplate possiamo indicare, definendo come risorsa o inline per la solo ComboBox, un DataTemplate da utizzare per ogni item.
ComboBox SelectedIndex="0" IsEditable="true" TextSearch.TextPath="@color"
ItemsSource="{Binding Source={StaticResource colors}}">
ComboBox.ItemTemplate>
DataTemplate>
StackPanel Margin="2" Orientation="Horizontal">
Rectangle Width="25" Height="25" Fill="{Binding XPath=@color}" />
TextBlock FontSize="15" Text="{Binding XPath=@color}" />
/StackPanel>
/DataTemplate>
/ComboBox.ItemTemplate>
/ComboBox>
All'interno di un template lo scope di binding è relativo al singolo item che stiamo caricando, perciò ci è concesso fare riferimento direttamente agli attributi dell'elemento item della sorgente. Nell'esempio disegniamo un rettangolo e una scritta relativi al colore corrente. Una menzione particolare la meritano le proprietà IsEditable e TextSearch.TextPath. La prima indica che la ComboBox è editabile e l'utente può immettere del testo di ricerca. La seconda è una attached property sull'oggetto TextSearch e ci permette di indicare qual è la proprietà sulla quale fare lookup per ogni ricerca che l'utente effettua. E' importante impostare questo path perché personalizzando il layout degli item il motore non è in grado di sapere qual è il testo rappresentativo dell'elemento. Il risultato di questa personalizzazione è il seguente, dove digitando "G" viene automaticamente suggerita la voce "Green".
martedì 10 marzo 2009
Aggiungere un Font alle risorse
Per aggiungere un font alle risorse è sufficiente aggiungerlo in una cartella del progetto, e dal controllo settare
FontFamily="Resources\#Onuava"
in questo modo verrà utilizzato questo font anzichè quello di default
FontFamily="Resources\#Onuava"
in questo modo verrà utilizzato questo font anzichè quello di default
Update in SQL, come inserire una datetime
L'update di un campo in SQL si fa così:
Per aggiornare più colonne:
Per inserire un valore DateTime:
UPDATE | Nome_Tabella |
SET | Nome_Colonna = Nuovo_Valore |
WHERE | Nome_Colonna = Un_Valore |
Per aggiornare più colonne:
UPDATE | Nome_Tabella |
SET | Nome_Colonna1 = Nuovo_Valore1 |
, Nome_Colonna2 = Nuovo_Valore2 | |
, Nome_Colonna3 = Nuovo_Valore3 | |
WHERE | Nome_Colonna = Un_Valore |
Per inserire un valore DateTime:
UPDATE | Nome_Tabella |
SET | Nome_Colonna = convert(datetime,'31122099') |
WHERE | Nome_Colonna = Un_Valore |
lunedì 9 marzo 2009
Progetto Setup, impostare TextBox Criptato
Tools
The only tool you need is ORCA. ORCA is a Microsoft utility for modifying and validating Windows Installer packages. It is a database tool created for setup authors and administrators who work with the Windows Installer Service. This utility is a part of the Windows Installer SDK download along with other MSI related tools.
You can use ORCA to open and modify MSI packages.
To download and install ORCA, follow these steps:
Visit the SDK Platform Site page to download the Windows Installer SDK. The link to Windows Installer SDK should be on the left hand side frame on the above site.
Click on that link to go to the next page to download Windows Installer SDK, which includes ORCA.
After downloading and installing Windows Installer SDK, go to \Program Files\Microsoft SDK\Bin folder on the machine to look for Orca.msi.
Run Orca.msi by double clicking on it, which is the setup to install ORCA on your machine.
After installing ORCA on your machine, you will be able to right click on any MSI package and open it in ORCA.
Using the code
The first thing to do, is generate our VS.NET setup project and identify our future password textbox. You can see Edit2Property in our example that is EDITA2.

Now, we start to modify the MSI to enable our password text changing attributes for our textbox EDITA2.
First of all, we've to start ORCA and open the MSI file generated by VS.NET, and go to 'Control' table.

Normally, all textboxes are called CustomTextA, and we've to identify our textbox by Property column. In our case, we can see our row, has '7' as attributes. Let's go to see what means this '7'.
The attributes are set in binary format, so '7' is 111. 100 + 10 + 1 and this is 4 + 2 + 1 in decimal format. Now, we can go to control attributes table here and check what attributes are 4,2,1.
We can see that our textbox has the following properties: Enabled, Sunken and Visible. Now, check that there's an advance properties table for textboxes, and there's a Password property with value 2097152.
Now we have to add this property to the initial property value (7). 2097152 + 7 = 2097159, that's our new property value. Set in attributes cell and save the MSI File.
Now, check your MSI, and you could see that our textbox is a password textbox!!!
The only tool you need is ORCA. ORCA is a Microsoft utility for modifying and validating Windows Installer packages. It is a database tool created for setup authors and administrators who work with the Windows Installer Service. This utility is a part of the Windows Installer SDK download along with other MSI related tools.
You can use ORCA to open and modify MSI packages.
To download and install ORCA, follow these steps:
Visit the SDK Platform Site page to download the Windows Installer SDK. The link to Windows Installer SDK should be on the left hand side frame on the above site.
Click on that link to go to the next page to download Windows Installer SDK, which includes ORCA.
After downloading and installing Windows Installer SDK, go to \Program Files\Microsoft SDK\Bin folder on the machine to look for Orca.msi.
Run Orca.msi by double clicking on it, which is the setup to install ORCA on your machine.
After installing ORCA on your machine, you will be able to right click on any MSI package and open it in ORCA.
Using the code
The first thing to do, is generate our VS.NET setup project and identify our future password textbox. You can see Edit2Property in our example that is EDITA2.

Now, we start to modify the MSI to enable our password text changing attributes for our textbox EDITA2.
First of all, we've to start ORCA and open the MSI file generated by VS.NET, and go to 'Control' table.

Normally, all textboxes are called CustomTextA, and we've to identify our textbox by Property column. In our case, we can see our row, has '7' as attributes. Let's go to see what means this '7'.
The attributes are set in binary format, so '7' is 111. 100 + 10 + 1 and this is 4 + 2 + 1 in decimal format. Now, we can go to control attributes table here and check what attributes are 4,2,1.
We can see that our textbox has the following properties: Enabled, Sunken and Visible. Now, check that there's an advance properties table for textboxes, and there's a Password property with value 2097152.
Now we have to add this property to the initial property value (7). 2097152 + 7 = 2097159, that's our new property value. Set in attributes cell and save the MSI File.
Now, check your MSI, and you could see that our textbox is a password textbox!!!
Iscriviti a:
Post (Atom)