Dynamic Properties allow you to show and edit properties that are assigned to a Vault category without the need to modify the XAML file.
When adding new properties to a Vault category, these properties appear automatically the next time the Data Standard dialog or tab is shown.
The dynamic properties are represented by a XAML DataGrid control that has two columns. The first column is read-only and shows the property name. The second column is more complex because it has to display different controls for different types (e.g., ComboBox for properties with a predefined list of values, DataPicker for properties of type date).
DataGrid Control
To add the Dynamic Properties control to dialog, the following lines are needed:
... <DataGrid x:Name="DSDynamicCategoryProperties" AutoGenerateColumns="False" HeadersVisibility="Column" ItemsSource="{Binding DynamicProperties}" ScrollViewer.CanContentScroll="False" HorizontalGridLinesBrush="WhiteSmoke" VerticalGridLinesBrush="WhiteSmoke"> <DataGrid.Columns> <DataGridTextColumn Binding="{Binding Name}" SortDirection="Ascending" Width="140" IsReadOnly="True" > <DataGridTextColumn.HeaderTemplate> <DataTemplate> <TextBlock Text="{Binding DataContext.UIString[LBL64], RelativeSource={RelativeSource AncestorType=DataGrid}}"/> </DataTemplate> </DataGridTextColumn.HeaderTemplate> </DataGridTextColumn> <DataGridTemplateColumn CellStyle="{StaticResource DynamicDataGridCellStyle}" Width="*" > <DataGridTemplateColumn.HeaderTemplate> <DataTemplate> <TextBlock Text="{Binding DataContext.UIString[LBL65], RelativeSource={RelativeSource AncestorType=DataGrid}}"/> </DataTemplate> </DataGridTemplateColumn.HeaderTemplate> </DataGridTemplateColumn> </DataGrid.Columns> </DataGrid> ...
The second column uses a style (CellStyle="{StaticResourceDynamicDataGridCellStyle}) that also has to be added to the XAML file in the Resources section. This takes care of all the different controls:
... <Window.Resources> <Style x:Key="DynamicDataGridCellStyle" TargetType="{x:Type DataGridCell}"> <Setter Property="Template"> <Setter.Value> <ControlTemplate> <ComboBox ItemsSource="{Binding ListValues}" Text="{WPF:ValidatedBinding Value}" IsEditable="True"></ComboBox> </ControlTemplate> </Setter.Value> </Setter> <Style.Triggers> <Trigger Property="IsSelected" Value="True"> <Setter Property="Background" Value="{DynamicResource {x:Static SystemColors.HighlightBrushKey}}"/> <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.HighlightTextBrushKey}}"/> <Setter Property="BorderBrush" Value="{DynamicResource {x:Static SystemColors.HighlightBrushKey}}"/> </Trigger> <Trigger Property="IsKeyboardFocusWithin" Value="True"> <Setter Property="BorderBrush" Value="{DynamicResource {x:Static DataGrid.FocusBorderBrushKey}}"/> </Trigger> <DataTrigger Binding="{Binding ListValues.Count}" Value="0"> <Setter Property="Template"> <Setter.Value> <ControlTemplate> <TextBox Text="{WPF:ValidatedBinding Value}"></TextBox> </ControlTemplate> </Setter.Value> </Setter> </DataTrigger> <DataTrigger Binding="{Binding Typ}" Value="DateTime"> <Setter Property="Template"> <Setter.Value> <ControlTemplate> <DatePicker SelectedDate="{WPF:ValidatedBinding Value, StringFormat='dd/MM/yyyy'}"/> </ControlTemplate> </Setter.Value> </Setter> </DataTrigger> <DataTrigger Binding="{Binding Typ}" Value="Bool"> <Setter Property="Template"> <Setter.Value> <ControlTemplate> <ComboBox Text="{WPF:ValidatedBinding Value}"> <system:Boolean>True</system:Boolean> <system:Boolean>False</system:Boolean> </ComboBox> </ControlTemplate> </Setter.Value> </Setter> </DataTrigger> </Style.Triggers> </Style> ...
XAML Binding DynamicProperties
Look at this line of code in the previous example:
ItemsSource="{Binding DynamicProperties}"
This code gets a list of IProperty elements that are assigned to the category. The IProperty object has, among others, these members which can be used in bindings:
XAML Binding DynamicPropertiesCategory
In order that the DynamicProperties binding returns something, a Vault category has to be specified first. In the default implementation that comes with Data Standard, the DynamicPropertiesCategory gets specified through a combo box:
... <ComboBox Name="Categories" ItemsSource="{Binding PsList[GetCategories]}" SelectedIndex="0" DisplayMemberPath="Name" SelectedItem="{Binding DynamicPropertiesCategory}" Text="{Binding Prop[_Category].Value}" Grid.Row="0" Grid.Column="1" IsEnabled="{Binding IsNewEntryDialog}"> </ComboBox> ...
The list of available Vault categories (ItemsSource="{Binding PsList[GetCategories]}") is returned by a PowerShell function GetCategories. In the default implementation, this just returns all categories. If only certain categories should be available (e.g., based on document type), this function has to be adjusted.
The selected category from the combo box sets the DynamicPropertiesCategory:
(SelectedItem="{Binding DynamicPropertiesCategory}")
Click here to learn more about Dynamic Property labels.