取消选择组合框中的数据

Deselect data in Combobox

我有一个带有数据集的组合框。

            <ComboBox
            Grid.Row="4" 
            Name="AddSubLocationCheckBox"
            Height="40"
            Background="White"
            Visibility="Visible"
            ItemsSource="{x:Bind ListLocations, Mode=OneWay}"
            VerticalAlignment="Top"
            HorizontalAlignment="Stretch"
            PlaceholderText="Set as Sub-Location"
            DisplayMemberPath="Name"
            SelectedItem="{x:Bind SelectedLocation, Mode=TwoWay}"
            Margin="0,30,10,0"/>

如果我选择了任何变体,如何取消选择此组合框中的选择?

我创建了一个新按钮 "Cancel" 用于在组合框中取消选择。这是一个简单的方法。我保留了组合框、按钮的代码属性和功能:

           <ComboBox
        Grid.Row="4" 
        Name="AddSubLocationCheckBox"
        Height="40"
        Width="300"
        Background="White"
        Visibility="Visible"
        ItemsSource="{x:Bind ListLocations, Mode=OneWay}"
        VerticalAlignment="Top"
        HorizontalAlignment="Left"
        PlaceholderText="Set as Sub-Location"
        DisplayMemberPath="Name"
        SelectedItem="{x:Bind SelectedLocation, Mode=TwoWay}"
        Margin="0,30,10,0"/>

        <Button
            Grid.Row="4"
            Name="CancelSubLocation"
            HorizontalAlignment="Right"
            VerticalAlignment="Top"
            Width="40"
            Height="40"
            Background="{StaticResource WhiteSolidColorBrush}"
            Tapped="CancelSubLocation_Tapped"
            Visibility="Visible"
            IsEnabled="False"
            Margin="0,30,10,0">
            <FontIcon Glyph="&#xE711;" Foreground="Black"/>
        </Button>

public ComboBoxLocationItem SelectedLocation
{
    get { return (ComboBoxLocationItem)GetValue(SelectedLocationProperty); }
    set { SetValue(SelectedLocationProperty, value); }
}

public static readonly DependencyProperty SelectedLocationProperty =
    DependencyProperty.Register(nameof(SelectedLocation), typeof(ComboBoxLocationItem), typeof(AddLocationControl), new PropertyMetadata(null,
        (o, args) => ((AddLocationControl)o).CheckSubLocation()));

public void CheckSubLocation()
{
        if (SelectedLocation != null)
        {
            CancelSubLocation.IsEnabled = true;
        }
        else
        {
            CancelSubLocation.IsEnabled = false;
        }
}

private void CancelSubLocation_Tapped(object sender, TappedRoutedEventArgs e)
{
    CancelSubLocation.IsEnabled = false;
    SelectedLocation = null;
}