xaml中绑定 <Shell.BackButtonBehavior> <BackButtonBehavior Command="{Binding GoBackCommand}"/> </Shell.BackButtonBehavior>然后在viewmodel中 async Task GoBackCommand() { //await Shell.Current.GoToAsync(".."); await Shell.Current.Navigation.PopAsync(); }但是会执行出错,你能知道为什么吗
时间: 2023-06-09 17:05:14 浏览: 35
根据你提供的信息,我无法确定错误的原因。但是我可以给你一些执行排错的建议:
1. 确保你的View中的Shell对象有正确的命名空间和引用。
2. 确保GoBackCommand方法在ViewModel中已正确实现,并且返回Task。
3. 确保绑定指向正确的GoBackCommand方法,方法名大小写要一致。
4. 有时候导航中有多个页时,可能需要使用Shell.Current.Navigation.PopModalAsync()方法来弹出页面而不是PopAsync()。
如果你还有其他具体的信息或错误提示,请提供给我,我会尽力帮助你解决问题。
相关问题
xaml中绑定 <Shell.BackButtonBehavior> <BackButtonBehavior Command="{Binding GoBackCommand}"/> </Shell.BackButtonBehavior>然后在viewmodel中 async Task GoBack() { //await Shell.Current.GoToAsync(".."); await Shell.Current.Navigation.PopAsync(); }但是会执行出错,你能知道为什么吗
根据您提供的信息,我可以推测出可能的问题是在绑定GoBackCommand时出现了问题。您需要在ViewModel中定义GoBackCommand,并将其绑定到XAML中的该属性。具体而言,您可以像下面这样定义GoBackCommand:
public ICommand GoBackCommand { get; }
public MainPageViewModel()
{
GoBackCommand = new Command(async () =>
{
await Shell.Current.Navigation.PopAsync();
});
}
然后,您可以使用以下方法将GoBackCommand绑定到Shell.BackButtonBehavior的Command属性:
<Shell.BackButtonBehavior>
<BackButtonBehavior Command="{Binding GoBackCommand}"/>
</Shell.BackButtonBehavior>
这应该可以解决您的问题。如果您有任何其他问题,请随时问我。
<DataGridTemplateColumn> <DataGridTemplateColumn.CellTemplate> <DataTemplate> <CheckBox HorizontalAlignment="Center" VerticalAlignment="Center" IsChecked="{Binding IsCheck,UpdateSourceTrigger=PropertyChanged}" x:Name="DTCB" Command="{Binding DataContext.SelectedCommand, RelativeSource={RelativeSource AncestorType=UserControl}}" CommandParameter="{Binding Cad_No}"> <CheckBox.InputBindings> <MouseBinding MouseAction="LeftClick"/> </CheckBox.InputBindings> </CheckBox> </DataTemplate> </DataGridTemplateColumn.CellTemplate> </DataGridTemplateColumn> 怎么让第一行的checkbox不显示
可以使用行样式(RowStyle)来隐藏第一行的 CheckBox。在 DataGrid 中设置 RowStyle 属性,然后使用 DataTrigger 来判断当前行是不是第一行,如果是第一行,则将 CheckBox 的 Visibility 属性设置为 Hidden。示例代码如下:
```
<DataGrid ...>
<DataGrid.RowStyle>
<Style TargetType="DataGridRow">
<Style.Triggers>
<DataTrigger Binding="{Binding RelativeSource={RelativeSource Self}, Path=IsNewItem}" Value="True">
<Setter Property="Visibility" Value="Collapsed"/>
</DataTrigger>
</Style.Triggers>
</Style>
</DataGrid.RowStyle>
...
<DataGridTemplateColumn>
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<CheckBox Visibility="{Binding RelativeSource={RelativeSource AncestorType=DataGridRow}, Converter={StaticResource FirstRowToVisibilityConverter}}"
... />
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
...
</DataGrid>
```
其中,FirstRowToVisibilityConverter 是一个实现了 IValueConverter 接口的转换器,用于将第一行转换为 Hidden,其他行转换为 Visible。具体实现可以参考以下代码:
```
public class FirstRowToVisibilityConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
var row = value as DataGridRow;
if (row != null && row.IsNewItem)
{
return Visibility.Collapsed;
}
return Visibility.Visible;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
```
需要在 XAML 中定义 FirstRowToVisibilityConverter,可以使用以下代码:
```
<Window.Resources>
<local:FirstRowToVisibilityConverter x:Key="FirstRowToVisibilityConverter" />
</Window.Resources>
```