UWP数据网格SelectedItem绑定不工作

UWP数据网格SelectedItem绑定不工作,uwp,datagrid,uwp-xaml,Uwp,Datagrid,Uwp Xaml,我正在尝试处理我的UWP应用程序的一个小问题。在下一页中,当使用AppBarButton编辑时,我希望将DataGrid的选定项绑定为CommandParameter,但它不起作用(使用null参数调用该命令)。出于故障排除的目的,我创建了TextBlockMyTextBlock,它的Text属性绑定到DataGrid的SelectedItem。但即使在选择一个项目后,TextBlok也不会更新。您是否看到下面的XAML页面有问题? 我已经用WPF做了很多年了,但是不能用UWP来做 提前感谢您的

我正在尝试处理我的UWP应用程序的一个小问题。在下一页中,当使用AppBarButton编辑时,我希望将DataGrid的选定项绑定为CommandParameter,但它不起作用(使用null参数调用该命令)。出于故障排除的目的,我创建了TextBlockMyTextBlock,它的Text属性绑定到DataGrid的SelectedItem。但即使在选择一个项目后,TextBlok也不会更新。您是否看到下面的XAML页面有问题? 我已经用WPF做了很多年了,但是不能用UWP来做

提前感谢您的建议

<Page x:Name="MyPage"
x:Class="MyApp.PageSites"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:WindowsTechnicianClient"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:uwp="using:Microsoft.Toolkit.Uwp.UI.Controls"
xmlns:base="using:Base"
mc:Ignorable="d"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<Page.Resources>
    <local:StaticMapper x:Key="Static"/>
</Page.Resources>
<Page.TopAppBar>
    <CommandBar ClosedDisplayMode="Compact" IsOpen="True">
        <CommandBar.PrimaryCommands>
            <AppBarElementContainer>
                <TextBlock x:Name="MyTextBox" Text="{Binding ElementName=MyDataGridSites, Path=SelectedItem}"/>
            </AppBarElementContainer>
            <AppBarButton Command="{x:Bind CommandEditItem}" CommandParameter="{Binding ElementName=MyDataGridSites, Path=SelectedItem}"
                          Icon="Edit" IsCompact="False" Label="Edit"/>
        </CommandBar.PrimaryCommands>
    </CommandBar>
</Page.TopAppBar>

    <uwp:DataGrid x:Name="MyDataGridSites" AlternatingRowBackground="WhiteSmoke" AutoGenerateColumns="False"
                  IsReadOnly="True" ItemsSource="{Binding Source={StaticResource Static}, Path=Sites}" SelectionMode="Single">
        <uwp:DataGrid.Columns>
            <uwp:DataGridTextColumn Binding="{Binding}" Header="Name"/>
            <uwp:DataGridTextColumn Binding="{Binding Path=Type}" Header="Type"/>
            <uwp:DataGridTextColumn Binding="{Binding Path=Address}" Header="Address"/>
            <uwp:DataGridTextColumn Binding="{Binding Path=Latitude}" Header="Latitude"/>
            <uwp:DataGridTextColumn Binding="{Binding Path=Longitude}" Header="Longitude"/>
        </uwp:DataGrid.Columns>
    </uwp:DataGrid>

我发现: CommandParameter=“{x:Bind MyDataGridSites.SelectedItem,Mode=OneWay}”


我发现: CommandParameter=“{x:Bind MyDataGridSites.SelectedItem,Mode=OneWay}”


    <Page.Resources>
    <local:StaticMapper x:Key="Static"/>
</Page.Resources>

    <uwp:DataGrid x:Name="MyDataGridSites" AlternatingRowBackground="WhiteSmoke" AutoGenerateColumns="False"
                  IsReadOnly="True" ItemsSource="{Binding Source={StaticResource Static}, Path=Sites}" SelectionMode="Single">
        <uwp:DataGrid.Columns>
            <uwp:DataGridTextColumn Binding="{Binding}" Header="Name"/>
            <uwp:DataGridTextColumn Binding="{Binding Path=Type}" Header="Type"/>
            <uwp:DataGridTextColumn Binding="{Binding Path=Address}" Header="Address"/>
            <uwp:DataGridTextColumn Binding="{Binding Path=Latitude}" Header="Latitude"/>
            <uwp:DataGridTextColumn Binding="{Binding Path=Longitude}" Header="Longitude"/>
        </uwp:DataGrid.Columns>
    </uwp:DataGrid>
<Page.TopAppBar>
    <CommandBar ClosedDisplayMode="Compact" IsOpen="True">
        <CommandBar.PrimaryCommands>
            <AppBarButton Command="{x:Bind CommandEditItem}" CommandParameter="{x:Bind MyDataGridSites.SelectedItem, Mode=OneWay}"
                          Icon="Edit" IsCompact="False" Label="Edit"/>
        </CommandBar.PrimaryCommands>
    </CommandBar>
</Page.TopAppBar>