NoesisGUI

Markup Extensions

Markup extensions are clases that provides values for object properties. When used in XAML, they are usually written in a compact form between curly braces "{}", but this sintax is semantically identical to the more usual Xaml mode of writing objects using nodes. Extensions expressed with {} can be nested.

Markup extensions implement the IMarkupExtension interface, which defines the ProvideValue unique method to return a value to the property that has the markup assigned.

MarkupExtension

http://msdn.microsoft.com/en-us/library/system.windows.markup.markupextension.aspx

Methods
Name Sup Comments
ProvideValue Yes Defined as IMarkupExtension::ProvideValue

NullExtension

http://msdn.microsoft.com/en-us/library/system.windows.markup.nullextension.aspx

The NullExtension is used to set a null value to properties that are components of nullables. The NullExtension has no possible attributes.

<ToggleButton IsChecked="{x:Null}"/>

StaticExtension

http://msdn.microsoft.com/en-us/library/system.windows.markup.staticextension.aspx

Returns a static value that is set in the static elements dictionary of the UISystem. The static list is filled when the UISystem is initialized, and it usually contains values that are dependant of the operating system, although any value could be stored here by the user calling IUISystem::SetStatic(). Static resources are referenced always by name.

<Style x:Key="{x:Static MenuItem.SeparatorStyleKey}">
  <Setter Property="Foreground" Value="{x:Static SystemColors.ControlTextBrushKey}"/>
</Style>
Properties
Name Sup Comments
Member Yes  
MemberType No  

TypeExtension

http://msdn.microsoft.com/en-us/library/system.windows.markup.typeextension.aspx

Returns the type of an object, encapsulated into a ResourceKeyType.

<Style TargetType="{x:Type RepeatButton}"/>
Properties
Name Sup Comments
Type Yes  
TypeName Yes Returns a Symbol

ArrayExtension

Is not currently supported in Noesis.

StaticResource

http://msdn.microsoft.com/en-us/library/system.windows.staticresourceextension.aspx

Allows searching for an resource in a ResourceDictionary at Xaml load time. The resource is searched in the resource dictionaries of the current parsing tree, looking upwards until the root is reached.

If the resource is not found, an exception is thrown; if the resource is found, the value is returned and the extension is deleted, so if later the resource entry is modified in the ResourceDictionary, the change is not seen by the extension's target object.

Generally, resources can are stored and accessed by name, but Style objects in resources can be accessed by type

<Page>
<Page.Resources>
  <SolidColorBrush x:Key="MyBrush" Color="Gold"/>
  <Style x:Key="{x:Type Button}">
</Style>

</Page.Resources>
  <StackPanel>
    <Ellipse Width="100" Height="100" Fill="{StaticResource MyBrush}"/>
    <Button Style="{StaticResource {x:Type Button}}"/>
  </StackPanel>
</Page>
Properties
Name Sup Comments
ResourceKey Yes  

DynamicResource

http://msdn.microsoft.com/en-us/library/system.windows.dynamicresourceextension.aspx

The DynamicResource is similar to the StaticResource, but it maintains an active look to the resource, so it the resource entry changes in the resourceDirectionary (the resource is deleted or changed, or one of the ancestors of the target object changes, for example) the DynamicResource detects the change and reassigns the new value to the target property.

Internally, the DynamicResourceExtension creates a DynamicResourceExpression, which is in charge of detecting the changes and updating the target values, just like a BindingExpression.

<Setter Property="BorderBrush" Value="{DynamicResource DefaultedBorderBrush}"/>
Properties
Name Sup Comments
ResourceKey Yes  

Binding and TemplateBinding

The other usual markup extension is Binding and TemplateBinding, which are explained here

© 2017 Noesis Technologies