Data Standard and Styles

Around hundred people in Europe have been trained on the Data Standard technology for Autodesk Vault. It was our pleasure to hold the trainings on behalf of Autodesk, and we like to keep the excitement on this topic high. Now, Data Standard builds on Microsoft technologies such as WPF and PowerShell, so the possibilities are endless. With a series of blogs, we like to add more information, tips and samples in order to extend the knowledge acquired during the training. In the training we spent a full day practicing the design of dialogs. At this point, I’d like to introduce styles.

Styles are a great way to set some default values for certain controls, such as color, layout, and other properties. Basically, all the properties that a control exposes can be set via a style. An example: suppose you have a customer who wants to have all the labels in dark green, as this is his company color. You either set each label to dark green, and this customer has 54 labels ( ☺ ), or you may configure a style for labels that sets the color to dark green. So, no matter where a label is used, it will be dark green.

This is how it looks when setting the color on each label:

<Label Foreground="DarkGreen" Content="Folder" Grid.Row="0" Grid.Column="0"/>
<TextBox Grid.Column="1" Grid.Row="0" Text="{Binding Prop[Folder].Value}" IsEnabled="{Binding CreateMode}"/>
<Label Content="*" Grid.Column="0" Grid.Row="0" Foreground="#FF0000" HorizontalAlignment="Right" FontWeight="Bold" />
<Label Foreground="DarkGreen" Content="Title" Grid.Column="0" Grid.Row="2"/>
<TextBox Text="{Binding Prop[GEN-TITLE-DES1].Value}" Grid.Column="1" Grid.Row="2" />
<Label Content="*" Grid.Column="0" Grid.Row="2" Foreground="#FF0000" HorizontalAlignment="Right" FontWeight="Bold" />
<Label Foreground="DarkGreen" Content="Description" Grid.Column="0" Grid.Row="4"/>
<TextBox Text="{Binding Prop[GEN-TITLE-DES2].Value}" Grid.Column="1" Grid.Row="4" Name="Description" VerticalScrollBarVisibility="Auto" MinHeight="50" MaxHeight="50" TextWrapping="Wrap" AcceptsReturn="True"/>
<Label Foreground="DarkGreen" Content="State" Grid.Column="0" Grid.Row="6"/>
<TextBox Text="" Grid.Column="1" Grid.Row="6" IsReadOnly="True" Background="#F0F0F0"/>
<Label Foreground="DarkGreen" Content="Path" Grid.Column="0" Grid.Row="8"/>

And here the according style:

<Style TargetType="Label">
  <Setter Property="Foreground" Value="DarkGreen"/>

As you can see, the syntax is pretty straightforward. At the top of your XAML file, in the Area of Resource (for example insode <prop:DSWindow.Resources>), you create your style and define with TargetType for which control the style should be. In my case the TargetType is Label, but of course it can be TextBox, CombBox, Grid, or whatever else. Inside the Style, you set the value of the property you like to change via a Setter (<Setter Property=”…” Value=”…”/>). You can of course set multiple properties within your style. Just replicate the <Setter /> line as many times as you need. Keep in mind that all the properties that a control exposes can be set via a setter, such as Visibility, IsEnabled, Margin, etc. So, if you like that all TextBox shall have a left margin of 5, then you can set it via a setter. Or for instance, if you have a tab where all TextBox or ComboBox shall not be editable, then just set the IsEnable to false as a style. The data sheet tabs delivered with Data Standard uses styles, so have a look to the Datasheet.xaml in the /Vault/Configuration/File folder and see how styles are used there.

I hope this may save you some time during the next Data Standard configuration. We keep posting on Data Standard, and if you have some topics of interest, just let us know, and we will see to talk about it.

This entry was posted in Data Standard, PowerShell. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s