Use the x:Set Markup Extension
masterThe {x:Set} markup extension allows you to set a property once using an expression. It is useful for one-time assignments that do not require change tracking.
Key differences between x:Set and x:Bind:
- Evaluation Timing:
x:Setexpressions are evaluated at the end of the constructor.x:Bindexpressions (whenx:DataTypeis specified) are evaluated when theDataContext/BindingContextis set. - Change Tracking:
x:Setdoes not generate code to listen for property changes. Forx:Bind, you must setMode=OneTimeif you do not want change tracking. - Data Root: The data root for
x:Setis always the view itself. The data root forx:Binddepends on thex:DataTypeattribute. Both support using static members in expressions.