NullableBoolExtension
The NullableBoolExtension
type provides the ability to set nullable bool
dependency properties in XAML markup. These types of properties can normally be bound to, but can't be explicitly set to a specific value. This extension provides that capability.
Platform APIs:
NullableBoolExtension
Here is an example of how this extension could be used when binding to a DependencyProperty
:
<Page.Resources
xmlns:ui="using:Microsoft.Toolkit.Uwp.UI"
xmlns:helpers="using:MyApp.Helpers">
<helpers:ObjectWithNullableBoolProperty
x:Key="OurObject"
NullableBool="{ui:NullableBool Value=True}"/>
</Page.Resources>
With the following backend object to use as binding source:
namespace MyApp.Helpers
{
public class ObjectWithNullableBoolProperty : DependencyObject
{
// Using a DependencyProperty as the backing store for NullableBool.
// This enables animation, styling, binding, etc...
public static readonly DependencyProperty NullableBoolProperty = DependencyProperty.Register(
nameof(NullableBool),
typeof(bool?),
typeof(ObjectWithNullableBoolProperty),
new PropertyMetadata(null));
public bool? NullableBool
{
get => (bool?)GetValue(NullableBoolProperty);
set => SetValue(NullableBoolProperty, value);
}
}
}
Examples
You can find more examples in the unit tests.
Feedback
https://aka.ms/ContentUserFeedback.
Coming soon: Throughout 2024 we will be phasing out GitHub Issues as the feedback mechanism for content and replacing it with a new feedback system. For more information see:Submit and view feedback for