{{Hint|There's no way to commit changes without saving them locally first. Therefore, the "AutoSave" parameter will be ignored when "AutoCommit" is set to true.}}
Here's an example of the command usage. It tries to set the property called "VALUE" to a double value 50 regardless of its current state and then automatically save and commit the change.
<br />
<source lang = "xml">
<AppBarButton xmlns:example="using:UBIK.WinX.Controls" ...<Button Command="{Binding SetPropertyValueCommand}" Icon Style="Edit{StaticResource UBIKButtonStyle}" Label Content="Set to 50%Property"> <AppBarButtonButton.CommandParameter> <examplecontrols:KeyValueList> <examplecontrols:KeyValueParameter Key="PropertyName" Value="VALUEMP_PROPERTY" /> <examplecontrols:KeyValueParameter Key="PropertyValue"> <example:KeyValueParameter.Value> <x:Double>50</x:Double> </example:KeyValueParameter.="My Value> <" /example:KeyValueParameter> <examplecontrols:KeyValueParameter Key="OnlyForUnvalidated" Value="false" /> <examplecontrols:KeyValueParameter Key="AutoSave" Value="true" /> <examplecontrols:KeyValueParameter Key="AutoCommit" Value="true" /> </examplecontrols:KeyValueList> </AppBarButtonButton.CommandParameter> </AppBarButtonButton>
</source>
{{Hint|It is advised to provide typed values like <nowiki><x:Double>50</x:Double></nowiki>. But for For simple types, you can try writing them in the text format like <nowiki><examplecontrols:KeyValueParameter Key="PropertyValue" Value="50" /></nowiki> and {{UBIK}} will try to find the right type. For advanced property types, it is advised to provide typed values like <nowiki><x:Boolean>true</x:Boolean></nowiki>.}}
<br>
==== Set a Binding as PropertyValue ====
There is a known issue in XAML where Behaviors and KeyValueLists do not inherit the binding context of the control they are attached to. Simply put, trying to use a binding directly in the PropertyValue part of the command; '''<nowiki><controls:KeyValueParameter Key="PropertyValue" Value="{Binding BindingPath}" /></nowiki>''', would lead to the client setting the value of MP_PROPERTY to null.
Luckily, there is a simple way to link this Binding to a context. Using the above example as a foundation, adapt the button as shown below:
<source lang = "xml">
<Button
x:Name="SetDynamicPropertyButton"
Tag="{Binding}"
... >
<Button.CommandParameter>
<controls:KeyValueList>
...
<controls:KeyValueParameter Key="PropertyValue" Value="{Binding Tag.BindingPath, ElementName=SetDynamicPropertyButton}" />
...
</controls:KeyValueList>
</Button.CommandParameter>
</Button>
</source>
The above code uses the x:Name of the button to specify the viewmodel from which we wish to begin our binding path.<br>
You do not need to follow this exact syntax, all that is necessary is to provide a connection to the BindingContext of an observable control.
==== Set Current DateTime ====
<tabs>
<tab name="UWP">
<source lang = "xml">
xmlns:example="using:UBIK.WinX.Controls"
...
<Button
x:Name="SetCurrentDateTimeButton"
Tag="{Binding}"
Command="{Binding SetPropertyValueCommand}"
Style="{StaticResource UBIKButtonStyle}"
Content="Set Property">
<Button.CommandParameter>
<controls:KeyValueList>
<controls:KeyValueParameter Key="PropertyName" Value="MP_PROPERTY" />
<controls:KeyValueParameter Key="PropertyValue" Value="{Binding Tag.AppStatus.LiveDateTime, ElementName=SetCurrentDateTimeButton}" />
<controls:KeyValueParameter Key="OnlyForUnvalidated" Value="false" />
<controls:KeyValueParameter Key="AutoSave" Value="true" />
<controls:KeyValueParameter Key="AutoCommit" Value="true" />
</controls:KeyValueList>
</Button.CommandParameter>
</Button>
</source>
</tab>
<tab name="Xamarin">
<Button
x:Name="SetCurrentDateTimeButton"
Command="{Binding SetPropertyValueCommand}"
Text="Set Property">
<Button.CommandParameter>
<classes:KeyValueList>
<classes:KeyValueParameter Key="PropertyName" Value="MP_PROPERTY" />
<classes:KeyValueParameter Key="PropertyValue" Value="{Binding BindingContext.AppStatus.LiveDateTime, Source={x:Reference SetCurrentDateTimeButton}}" />
<classes:KeyValueParameter Key="OnlyForUnvalidated" Value="false" />
<classes:KeyValueParameter Key="AutoSave" Value="true" />
<classes:KeyValueParameter Key="AutoCommit" Value="true" />
</classes:KeyValueList>
</Button.CommandParameter>
</Button>
</tab>
</tabs>
[[Category:Client|XAML Tips]]
[[Category:WinX|XAML Tips]]
[[Category:XAML|XAML Tips]]
[[Category:Xamarin|XAML Tips]]
=== SaveAndCommitCommand ===