ParameterizedResource en - Leksiqq/WpfMarkupExtension GitHub Wiki
Attention! This article, as well as this announcement, are automatically translated from Russian.
Used in XAML markup similar to <StaticResource> or {StaticResource ResourceKeyValue}. It works in the same way, but if the $ symbol is found in the value of some attributes, it determines it as the beginning of the parameter name and tries to substitute the specified replacement for the parameter.
parameter search is performed:
- In
<Binding>or{Binding ... }elementsPathElementNameConverterParameterSourceXPath
- In
<MultiBinding>elementsConverterParameter
- In
<l:ParameterizedResource>elements (assuming a prefix is declared:xmlns:l="clr-namespace:Net.Leksi.WpfMarkup;assembly=Net.Leksi.WpfMarkupExtension") *ResourceKey
Important! Note that when using parameters, the resource must be declared with the x:Shared="False" attribute, otherwise the substitution will only be done once, when a single instance is created!
-
public static bool DefaultStrict { get; set; } = false;- default value for theStrictproperty of class instances. -
ResourceKey- Gets or sets the key value passed by this static resource reference. The key is used to return an object that has the corresponding key in the resource dictionary. Syntax options:- in attribute:
{l:ParameterizedResource ResourceKeyValue ... } - in element:
- in attribute:
<l:ParameterizedResource ResourceKey="ResourceKeyValue"/>
-
Replacesis an array of strings or/andBindingProxydescribing parameter substitutions. Inherited by upstreamProvideValuecalls on the stack. If substitution is required, the latest definition encountered in theProvideValuecall stack is used. Syntax options:- in attribute:
{l:ParameterizedResource ResourceKeyValue, Replaces=$param1:replace1|$param2:replace2... }- only strings can be used; - in element:
- in attribute:
<l:ParameterizedResource ResourceKey="ResourceKeyValue">
<x:Array Type="sys:String">
<sys:String>$param1:replace1</sys:String>
<sys:String>$param2:replace2</sys:String>
<l:BindingProxy Name="$param3" Value="{Binding ...}"/>
<l:BindingProxy Name="$param4" Value="{x:Null}"/>
...
</x:Array>
...
</l:ParameterizedResource>
or
<l:ParameterizedResource ResourceKey="ResourceKeyValue">
<l:ParameterizedResource.Replaces>
<x:Array Type="sys:String">
<sys:String>$param1:replace1</sys:String>
<sys:String>$param2:replace2</sys:String>
<l:BindingProxy Name="$param3" Value="{Binding ...}"/>
<l:BindingProxy Name="$param4" Value="{x:Null}"/>
...
</x:Array>
</l:ParameterizedResource.Replaces>
...
</l:ParameterizedResource>
-
Defaultsarray of strings describing parameter substitutions. Not inherited by upstreamProvideValuecalls on the stack. If a parameter is set to a default value, then it is substituted when the corresponding substitution is not previously set in theProvideValuecall stack. Syntax options:- in attribute:
{l:ParameterizedResource ResourceKeyValue, Defaults=$param1:default1|$param2:default2... } - in element:
- in attribute:
<l:ParameterizedResource ResourceKey="ResourceKeyValue">
<l:ParameterizedResource.Defaults>
<x:Array Type="sys:String">
<sys:String>$param1:default1</sys:String>
<sys:String>$param2:default2</sys:String>
...
</x:Array>
</l:ParameterizedResource.Defaults>
...
</l:ParameterizedResource>
-
Atis an arbitrary string label to track when debugging (seeVerbosebelow). Syntax options:- in attribute:
{l:ParameterizedResource ResourceKeyValue, At=AtValue ... } - in element:
- in attribute:
<l:ParameterizedResource ResourceKey="ResourceKeyValue" At="AtValue"/>
-
Verbose- verbosity of output to the console during debugging, by default -0- no output. The value1causesProvideValuecalls and actions with parameters to be output to the console: substitution inheritance and substitutions themselves; the value2, except for the listed one, displays all checked elements of the logical and visual trees. Note that the application must be compiled as a "Console Application" in order to be output to the console. Syntax options:- in attribute -
{l:ParameterizedResource ResourceKeyValue, Verbose=VerboseValue ... } - in element:
- in attribute -
<l:ParameterizedResource ResourceKey="ResourceKeyValue", Verbose="VerboseValue"/>
-
Strict- boolean variable, default - value of the static propertyDefaultSrict- throwsSystem.Windows.Markup.XamlParseExceptionif some parameter is not substituted. A value offalsecauses the appropriate message to be printed to the console, provided that the application is compiled as a "Console Application". Syntax options:- in attribute -
{l:ParameterizedResource ResourceKeyValue, Strict=False... } - in element:
- in attribute -
<l:ParameterizedResource ResourceKey="ResourceKeyValue", Strict="False"/>
-
AsValueOfType- variable ofTypetype,nullby default. If notnull, converts the value ofResourceKeyto the specified type. Syntax options:- in attribute -
{l:ParameterizedResource ResourceKeyValue, AsValueOfType={x:Type TypeName}... } - in element:
- in attribute -
<l:ParameterizedResource ResourceKey="ResourceKeyValue", AsValueOfType="{x:Type TypeName}"/>
For example:
<DataGrid ItemsSource="{Binding KeysViewSource.View}" AutoGenerateColumns="False" Margin="10,10,10,10">
<DataGrid.Resources>
<local:KeyValueDataTemplateSelector x:Key="KeyValueTemplate" x:Shared="False"
IsEditing="{l:ParameterizedResource $IsEditing, AsValueOfType={x:Type sys:Boolean}}">
<local:KeyValueDataTemplateSelector.View>
<data template>
<TextBlock Text="{Binding Item2}"/>
</Data Template>
</local:KeyValueDataTemplateSelector.View>
<local:KeyValueDataTemplateSelector.Edit>
<data template>
<TextBox Text="{Binding Item2}"/>
</Data Template>
</local:KeyValueDataTemplateSelector.Edit>
</local:KeyValueDataTemplateSelector>
</DataGrid.Resources>
<DataGrid.Columns>
<DataGridTextColumn Header="Key" Binding="{Binding Item1}" IsReadOnly="True"/>
<DataGridTemplateColumn Header="Value"
CellTemplateSelector="{l:ParameterizedResource KeyValueTemplate, Replaces=$IsEditing:False}"
CellEditingTemplateSelector="{l:ParameterizedResource KeyValueTemplate, Replaces=$IsEditing:True}"
/>
</DataGrid.Columns>
</DataGrid>
As examples, it is proposed to trace in demo on the tab "Demo2" the templates CellTemplateSelector and CellEditingTemplateSelector in DataGrid and resources for them in the file Dictionary2.xaml.
Before: (StyleCombiner) Start:(Overview) Next:(XamlServiceProviderCatcher)