fortran-iso-c-binding 相关问题


在 Apple Silicon 上进行 x86 编译的 Fortran/C 程序

我正在尝试编译一个用Fortran编写的软件,它还需要一些用C编写的库。该软件最初是为了在x86 Linux架构上编译而编写的,但我正在尝试


dlmopen 可以用作 dlopen 的“直接”替代品吗?

我有一个非线程安全共享库(C/Fortran),即它使用定义其状态的全局变量。因此,当我使用 dlopen 从同一进程多次打开该库时,全局变量...


在PHP中打印文件修改时间ISO-8601格式[重复]

我试图回显文件的上次更新时间并将其显示为 ISO-8601 时间戳格式。我尝试了一些命令,但它们没有获得正确的上次修改日期。 我试过: 我正在尝试 echo 文件的上次更新时间并将其显示为 ISO-8601 时间戳格式。我尝试了一些命令,但它们没有获得正确的上次修改日期。 我尝试过: <?php echo date("c"); ?> 但它只获取当前服务器时间,就像2024-01-11T11:39:33+02:00一样,它总是在变化。与date('c', time())相同。 以下两个似乎得到以下日期:1970-01-01T02:00:00+02:00: $lastmod = date('Y-m-dTH:i:s+00:00'); echo date('c', $timestamp) 和 $lastmod = date('Y-m-d\TH:i:s'); $tzd = date('Z'); $lastmod .= ($tzd < 0)? "-".gmdate('H:i', -$tzd) : "+".gmdate('H:i', $tzd); echo date('c', $timestamp) 我想要最后修改的 PHP/HTML 文件日期(时间戳);如果是两天前编辑的,则会显示日期等 您可以使用 PHP 中的 filemtime 函数来获取 ISO-8601 格式的文件的最后修改时间: $filename = 'path/to/your/file.php'; // Replace with your file path if (file_exists($filename)) { $lastModified = filemtime($filename); echo date('c', $lastModified); } else { echo "The file does not exist."; }


使用自定义比较函数时,无法将“[ExpressionColumn]”类型的值转换为预期参数类型“Binding<C>””

我在 SwiftUI 中遇到一个问题,我尝试使用 ForEach 循环来迭代结构数组 (v.columns) 并根据条件更新属性。该结构有一个


创建可启动的.iso文件 - 从clonezilla制作的图像文件夹

我的主要目标是保存现有的!虚拟机!完全地。到可启动的 .iso 文件。 从原始虚拟机创建许多其他虚拟机 >> 就像从 .iso 安装 Linux 一样 去...


GFortran 错误:ld:尝试编译时未找到 -lSystem 的库

尝试使用 gfortran 编译简单的 fortran-90 文件时遇到奇怪的错误。我正在开发 macOS mojave 系统。我安装了 gfortran 8.2.0,并通过


Java Web App - 尝试运行 JSP 文件 (IntelliJ) 时出现错误 404

当我尝试运行 JSP 文件(右键单击文件名并在 IntelliJ 中运行)时,我得到 404 我的JSP代码: `<%@ page contentType="text/html; charset=ISO-8859-1" pageEncoding=...


使用 openmp 并行化 N 体模拟

我正在尝试并行化 Fortran 代码以进行 N 体模拟,但与顺序版本相比,它总是需要更长的执行时间,并且执行时间随着 nu 的增加而增加...


client.c:178:24:错误:调用未声明的函数“rb_tainted_str_new2”; ISO C99 及更高版本不支持隐式函数声明

我尝试在 macOS Sonoma 14.2.1 上安装 mysql2 gem 并首先收到错误: > 宝石安装 mysql2 ... ld:找不到库“zstd” ... 然后: > gem install mysql2 -- --with-ldflags=-L(b...


iOS 显示与 Android .Net MAUI Telerik 不同

我有以下适用于 Android 和 iOS 的代码,但是当运行和显示它时,一切都变得不正常或移动,这是为什么? 我有以下适用于 Android 和 iOS 的代码,但是当运行和显示它时,一切都变得不正常或移动,这是为什么? <telerik:RadListView x:Name="listView" ItemsSource="{Binding SPagina}" Margin="10" BackgroundColor="LightGray"> <telerik:RadListView.ItemTemplate > <DataTemplate> <telerik:ListViewTemplateCell > <telerik:ListViewTemplateCell.View> <StackLayout Margin="0,0,0,10" BackgroundColor="LightGray"> <telerik:RadBorder BorderColor="#44185f" Margin="0,1,0,1" CornerRadius="5" BorderThickness="3" Background="White" Padding="7"> <Grid > <Grid.ColumnDefinitions> <ColumnDefinition Width="Auto" /> <ColumnDefinition Width="*" /> <ColumnDefinition Width="Auto" /> <ColumnDefinition Width="*" /> </Grid.ColumnDefinitions> <Grid.RowDefinitions> <RowDefinition Height="Auto"/> <RowDefinition Height="10"/> <RowDefinition Height="Auto"/> <RowDefinition Height="10"/> <RowDefinition Height="Auto"/> <RowDefinition Height="10"/> <RowDefinition Height="Auto"/> </Grid.RowDefinitions> <Label Grid.Row="0" Grid.ColumnSpan="6" TextColor="#3A023A" Text="{Binding TituloPublicacion}" FontSize="16" FontAttributes="Bold" FontFamily="Arial"/> <Label Grid.Row="2" Grid.Column="0" Text="Tipo:" FontSize="14"/> <Label Grid.Row="2" Grid.Column="1" Text="{Binding Tipo}" FontSize="14"/> <Label Grid.Row="2" Grid.Column="2" Text="Año:" FontSize="14"/> <Label Grid.Row="2" Grid.Column="3" Text="{Binding Anio}" FontSize="14"/> <Label Grid.Row="4" Grid.Column="0" Grid.ColumnSpan="2" Text="Congreso/Revista:" FontSize="14"/> <Label Grid.Row="4" Grid.Column="2" Grid.ColumnSpan="2" Text="{Binding RevistaCongreso}" FontSize="14"/> <Label Grid.Row="6" Grid.Column="0" Text="Autores: " FontSize="12"/> <Label Grid.Row="6" Grid.Column="1" Grid.ColumnSpan="6" Text="{Binding Autores}" FontSize="12"/> </Grid> </telerik:RadBorder> </StackLayout> </telerik:ListViewTemplateCell.View> </telerik:ListViewTemplateCell> </DataTemplate> </telerik:RadListView.ItemTemplate> 问题是两个设备上的视图看起来不同。 我放置了以下示例图像。 安卓: iOS: 为什么会出现这种情况? ... RadListView 是他们的 ListView 版本,请改用他们的 CollectionView :https://www.telerik.com/maui-ui/collectionview <telerik:RadCollectionView x:Name="collectionView" ItemsSource="{Binding SPagina}" Margin="10" BackgroundColor="LightGray">


NET MAUI 有自动绑定功能吗?

我看到了一个非常奇怪的行为,我创建了一个名为 ObservationsListView 的 ContentView 我看到了一个非常奇怪的行为,我创建了一个名为 ObservationsListView 的 ContentView <Grid x:Class="NedChatApp.Custom.ObservationsListView" xmlns="http://schemas.microsoft.com/dotnet/2021/maui" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:custom="clr-namespace:NedChatApp.Custom" xmlns:modelObs="clr-namespace:NedChatApp.Models.Observations" Padding="10" x:DataType="custom:ObservationsListView"> <Frame Style="{StaticResource CardView}"> <VerticalStackLayout Grid.Column="1" Padding="10" Spacing="10" VerticalOptions="Center"> <Label HorizontalOptions="Center" Style="{StaticResource MediumLabelBold}" Text="{Binding ClassName}" /> <CollectionView ItemsSource="{Binding Observations}" SelectionMode="None"> <CollectionView.ItemTemplate> <DataTemplate x:DataType="modelObs:ObservationStudentComplete"> <custom:ObservationView Icon="{Binding Icon}" IsNegative="{Binding IsNegative}" ObservationText="{Binding ObservationText}" /> </DataTemplate> </CollectionView.ItemTemplate> </CollectionView> </VerticalStackLayout> </Frame> </Grid> CS 是 public partial class ObservationsListView : Grid { public static readonly BindableProperty ClassNameTextProperty = BindableProperty.Create(nameof(ClassName) , typeof(string) , typeof(ObservationsListView) , null , propertyChanged: (bindable, value, newValue) => ((ObservationsListView)bindable).ClassName = (string)newValue); public string ClassName { get => (string)GetValue(ClassNameTextProperty); set => SetValue(ClassNameTextProperty, value); } public static readonly BindableProperty ObservationsProperty = BindableProperty.Create(nameof(Observations) , typeof(List<ObservationStudentComplete>) , typeof(ObservationsListView) , new List<ObservationStudentComplete>() , propertyChanged: (bindable, value, newValue) => ((ObservationsListView)bindable).Observations = (List<ObservationStudentComplete>)newValue); public List<ObservationStudentComplete> Observations { get => (List<ObservationStudentComplete>)GetValue(ObservationsProperty); set => SetValue(ObservationsProperty, value); } public ObservationsListView() { InitializeComponent(); } } 我在这样的页面中使用它 <CollectionView x:Name="ObservationsList" HeightRequest="{Binding ObservationsHeight}" ItemsSource="{Binding Observations}" SelectionMode="None"> <CollectionView.ItemTemplate> <DataTemplate x:DataType="modelObs:ClassObservationReactions"> <custom:ObservationsListView Observations="{Binding Observations}" /> </DataTemplate> </CollectionView.ItemTemplate> </CollectionView> 这是使用的模型,ClassObservationReactions public class ClassObservationReactions { public long ClaseId { get; set; } public string ClassName { get; set; } public DateTime Date { get; set; } public List<ObservationStudentComplete> Observations { get; set; } } 奇怪的是,即使控件中未设置 ClassName,它在运行应用程序时仍然显示正确的值,那么是否存在某种自动绑定? 如果我尝试像这样手动绑定值 <custom:ObservationsListView ClassName="{Binding ClassName}" Observations="{Binding Observations}" /> 我收到此错误 找不到“ClassName”的属性、BindableProperty 或事件,或者值和属性之间的类型不匹配。 在 .NET MAUI 中,CollectionView 和 ListView 等视图通过使用 ItemTemplate 支持数据绑定。您所说的“自动绑定”概念可能描述了 ItemTemplate 如何自动绑定到 ItemsSource 提供的集合中的每个项目。简单来说,当 ItemsSource 绑定到集合时,框架会自动将该集合中的每个项目绑定到 ItemTemplate 上,确保每个数据项都按照模板显示。 关于第二点,看起来您正在尝试在自定义 ClassName 中设置 ContentView 属性,但在相应的代码隐藏文件中,只有两个 BindableProperty 定义: ClassNameText 和 Observations。如果我理解正确,这可能是模型属性和视图属性之间的混淆。要解决此问题,您应该按如下方式修改绑定: <custom:ObservationsListView ClassNameText="{Binding ClassName}" Observations="{Binding Observations}" />


当我在 Visual Studio 的 cmd 提示符下运行 ifort 编译器时,为什么出现“WindowsSdkDir”未找到警告

我使用Visual Studio 2008和并行工作室xe2011来做Fortran代码,有时我也使用Visual Studio 2022社区版本。我在外部工具中设置了 ifort 编译器的 cmd 提示符...


子控件中的绑定命令?

我有一个 UserControl,用作窗口对话框的“模板”。 它包含一个关闭按钮和一个取消按钮。 我有一个 UserControl,用作窗口对话框的“模板”。 它包含一个关闭按钮和一个取消按钮。 <UserControl x:Class="TombLib.WPF.Controls.WindowControlButtons" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:local="clr-namespace:TombLib.WPF.Controls" mc:Ignorable="d" xmlns:darkUI="clr-namespace:DarkUI.WPF;assembly=DarkUI.WPF" xmlns:vm="clr-namespace:TombLib.WPF.ViewModels" xmlns:sg="clr-namespace:SpacedGridControl;assembly=SpacedGridControl" d:DesignHeight="100" d:DesignWidth="300" x:Name="root"> <StackPanel VerticalAlignment="Center" HorizontalAlignment="Right" Height="Auto" Orientation="Horizontal"> <Button Name="oKButton" Margin="{x:Static darkUI:Defaults.MediumThickness}" Width="100" Height="Auto" Command="{Binding Close}" CommandParameter="{Binding Window}" Content="OK"></Button> <Button Name="cancelButton" Margin="{x:Static darkUI:Defaults.MediumThickness}" Width="100" Height="Auto" Command="{Binding Path=Cancel}" CommandParameter="{Binding Window}" Content="Cancel"></Button> </StackPanel> </UserControl> public partial class WindowControlButtons : UserControl { public static readonly DependencyProperty CancelProperty = DependencyProperty.Register( nameof(Cancel), typeof(ICommand), typeof(WindowControlButtons), new PropertyMetadata(null)); public ICommand Cancel { get { return (ICommand)GetValue(CancelProperty); } set { SetValue(CancelProperty, value); } } public static readonly DependencyProperty CloseProperty = DependencyProperty.Register( nameof(Close), typeof(ICommand), typeof(WindowControlButtons), new PropertyMetadata(null)); public ICommand Close { get { return (ICommand)GetValue(CloseProperty); } set { SetValue(CloseProperty, value); } } public static readonly DependencyProperty WindowParameter = DependencyProperty.Register( nameof(Window), typeof(object), typeof(WindowControlButtons), new PropertyMetadata(null)); public object? Window { get { return GetValue(WindowParameter); } set { SetValue(WindowParameter, value); } } public WindowControlButtons() { InitializeComponent(); } } 我想在以下窗口中使用它: <Window x:Class="TombLib.WPF.Windows.SelectIdWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:local="clr-namespace:TombLib.WPF.Windows" mc:Ignorable="d" xmlns:ctrl="clr-namespace:TombLib.WPF.Controls" xmlns:vm="clr-namespace:TombLib.WPF.ViewModels" xmlns:sg="clr-namespace:SpacedGridControl;assembly=SpacedGridControl" xmlns:darkUI="clr-namespace:DarkUI.WPF;assembly=DarkUI.WPF" Title="SelectIdWindow" Height="100" Width="300" d:DataContext="{d:DesignInstance Type=vm:SelectIdViewModel }" x:Name="Self"> <sg:SpacedGrid Margin="{x:Static darkUI:Defaults.MediumThickness}"> <!-- REDACTED --> <ctrl:WindowControlButtons DataContext="{Binding ElementName=Self}" Window="{Binding ElementName=Self, Mode=OneWay}" Close="{Binding CloseCommand,Mode=OneWay}" Cancel="{Binding CancelCommand,Mode=OneWay}" Height="Auto" Width="Auto" Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2" HorizontalAlignment="Right"/> </sg:SpacedGrid> </Window> public partial class SelectIdWindow : Window { public ICommand? CloseCommand { get; set; } public ICommand? CancelCommand { get; set; } public SelectIdWindow() { CloseCommand = new WindowCloseCommand(); InitializeComponent(); } } public class SelectIdViewModel { public string RequestedId { get; set; } = string.Empty; public IEnumerable<string> TakenIds { get; set;} public SelectIdViewModel(IEnumerable<string> takenIDs) { TakenIds = takenIDs; } } 但是,当我打开窗口时如下: SelectIdWindow w = new SelectIdWindow(); var takenIDs = Entities.Select(kv => kv.Key.Name); w.DataContext = new SelectIdViewModel(takenIDs); w.ShowDialog(); 我在绑定 WindowControlButtons 时收到以下错误: DataContext 显式设置为 Self,它应该代表 Window,而不是 ViewModel。我在这里做错了什么? 绑定错误表明问题出在 Button.ICommand 属性上: 要修复此问题,请在 WindowControlButtons 绑定中添加 ElementName=root,以便绑定到声明的依赖项属性而不是 DataContext: <UserControl x:Class="TombLib.WPF.Controls.WindowControlButtons" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:local="clr-namespace:TombLib.WPF.Controls" mc:Ignorable="d" xmlns:darkUI="clr-namespace:DarkUI.WPF;assembly=DarkUI.WPF" xmlns:vm="clr-namespace:TombLib.WPF.ViewModels" xmlns:sg="clr-namespace:SpacedGridControl;assembly=SpacedGridControl" d:DesignHeight="100" d:DesignWidth="300" x:Name="root"> <StackPanel VerticalAlignment="Center" HorizontalAlignment="Right" Height="Auto" Orientation="Horizontal"> <Button Name="oKButton" ... Command="{Binding Close, ElementName=root}" CommandParameter="{Binding Window, ElementName=root}" Content="OK"/> <Button Name="cancelButton" ... Command="{Binding Path=Cancel, ElementName=root}" CommandParameter="{Binding Window, ElementName=root}" Content="Cancel"/> </StackPanel> </UserControl>


将属性值从父级用户控件传递到子级的 DependencyProperty

如何将属性(SomeProperty)从ParentUserControl上下文传递到ChildUserControl的DependencyProperty(MyDProperty)? 在 XAML 中,它应该是: 如何将 ParentUserControl 上下文中的 property (SomeProperty) 传递到 ChildUserControl 的 DependencyProperty (MyDProperty)? 在XAML中,应该是: 但是,由于某种原因,MyDProperty 永远不会使用 Parent.DataContext.SomeProperty 设置。 就我而言,我正在传递一个操作,但这并不重要。我认为问题出在绑定上。 家长用户控制: public Action RemoveEsl1 => throw new NotImplementedException(); <uc:ChildUserControl Title="ESL 1" RemoveEslAction="{Binding RemoveEsl1}" DataContext="{Binding Esl1}"/> 子用户控件: public static readonly DependencyProperty RemoveEslActionProperty = DependencyProperty.Register(nameof(RemoveEslAction), typeof(Action), typeof(ChildUserControl), new PropertyMetadata(delegate { })); public Action RemoveEslAction { get => (Action)GetValue(RemoveEslActionProperty); set => SetValue(RemoveEslActionProperty, value); } 我在这里找到了各种技巧,但没有一个适合我或有效。 回答我自己的问题(检查 ParentUserControl): 型号: public class RootModel : ViewModelBase { private ParentModel parentModel = new(); public ParentModel ParentModel { get => parentModel; set => RisePropertyChanged(ref parentModel, value); } } public class ParentModel : ViewModelBase { private ChildModel childModel = new(); public ChildModel ChildModel { get => childModel; set => RisePropertyChanged(ref childModel, value); } public string ParentModelProperty => "Correct value from ParentModel"; } public class ChildModel : ViewModelBase { private string childModelProperty = "Wrong default value from ChildModel"; public string ChildModelProperty { get => childModelProperty; set => RisePropertyChanged(ref childModelProperty, value); } } 主窗口: <Window.DataContext> <model:RootModel/> </Window.DataContext> <uc:ParentUserControl DataContext="{Binding ParentModel}"/> 家长用户控件: <uc:ChildUserControl ChildDependency="{Binding DataContext.ParentModelProperty, RelativeSource={RelativeSource AncestorType=UserControl}}" DataContext="{Binding ChildModel}"/> 子用户控件: <StackPanel> <Label Content="Dependency property:"/> <Label Content="{Binding ChildDependency, RelativeSource={RelativeSource AncestorType=UserControl}}"/> <Separator/> <Label Content="Property:"/> <Label Content="{Binding ChildModelProperty}"/> </StackPanel> public partial class ChildUserControl : UserControl { public static readonly DependencyProperty ChildDependencyProperty = DependencyProperty.Register(nameof(ChildDependency), typeof(string), typeof(ChildUserControl), new ("Wrong default DP value from ChildUserControl")); public string ChildDependency { get => (string)GetValue(ChildDependencyProperty); set => SetValue(ChildDependencyProperty, value); } public ChildUserControl() { InitializeComponent(); } } 这就是如何将属性 (SomeProperty) 从 ParentUserControl 上下文传递到 ChildUserControl 的 DependencyProperty (MyDProperty)。


ClosedXML 导出数据网格到 Excel 仅 10 行

我有一个包含 60 行数据的数据网格和一个将其导入 Excel 的按钮: 我有一个包含 60 行数据的数据网格和一个将其导入 Excel 的按钮: <DataGrid AutoGenerateColumns="False" ItemsSource="{Binding Source}" CanUserAddRows="False" HeadersVisibility="All" Name="dgDisplay"> <DataGrid.Columns> <DataGridTextColumn Header="Day" Binding="{Binding Day}"/> <DataGridTextColumn Header="Data" Binding="{Binding Data}"/> </DataGrid.Columns> </DataGrid> <Button Command="{Binding SaveDataGridToExcelCommand}" CommandParameter="{Binding ElementName=dgDisplay}"/> 其中 Day 和 Data 只是一些随机生成的 int 数据。 我的代码使用 ClosedXML 将数据从中导出到 Excel,它使用 MainWindowViewModel: ObservableObject 调用 MVVM.Toolkit。 [RelayCommand] public void SaveDataGridToExcel(DataGrid dataGrid) { DataTable dt = new DataTable(); foreach (DataGridColumn column in dataGrid.Columns) { dt.Columns.Add(column.Header.ToString()); } foreach (var item in dataGrid.Items) { DataRow dr = dt.NewRow(); bool rowHasData = false; for (int i = 0; i < dataGrid.Columns.Count; i++) { var cellContent = dataGrid.Columns[i].GetCellContent(item); if (cellContent is TextBlock textBlock) { //check if row empty, dont add this row.I add it on purpose to check //if the datagrid recognite the rest 50 rows not have data. It actually //dont save those data dr[i] = textBlock.Text; if (!string.IsNullOrEmpty(textBlock.Text)) { rowHasData = true; } } } if (rowHasData) { dt.Rows.Add(dr); } } SaveFileDialog saveFileDialog = new SaveFileDialog(); saveFileDialog.Filter = "Excel files (*.xlsx)|*.xlsx"; if (saveFileDialog.ShowDialog() == DialogResult.OK) { using (XLWorkbook wb = new XLWorkbook()) { wb.Worksheets.Add(dt, "Sheet1"); wb.SaveAs(saveFileDialog.FileName); } } } 但是保存的60行结果只显示了10行数据,其余50行都是空的。如果疑问为什么不使用Microsoft.Interop.Excel,那是因为该包不适合我的 Excel 版本。我没有在 ClosedXML 中看到任何对此有限制或许可的地方,所以我想知道为什么。如有任何帮助,我们将不胜感激。 在浏览 github 几个小时后,我自己找到了答案。 我没有访问单元格内容,而是直接从 DataGrid 的 ItemsSource 访问数据: public void SaveDataGridToExcel(DataGrid dataGrid) { DataTable dataTable = new DataTable(); foreach (DataGridColumn column in dataGrid.Columns) { dataTable.Columns.Add(column.Header.ToString()); } var itemsSource = dataGrid.ItemsSource as IEnumerable; if (itemsSource != null) { foreach (var item in itemsSource) { var properties = item.GetType().GetProperties(); var row = dataTable.NewRow(); foreach (var property in properties) { row[property.Name] = property.GetValue(item); } dataTable.Rows.Add(row); } } //show dialog... }


为什么在VB.NET中没有出现Binding Combobox usingdictionary with the MS ACCESS database with dapper

我正在尝试使用VB.NET中的dapper将字典与MS ACCESS数据库绑定组合框。 所以我希望使用字典的绑定出现在组合框中,这是表的结果


将值从用户控件传递到同一用户控件wpf c#中的另一个?

我有四个用户控件,我尝试将值从用户控件传递到另一个用户控件,这些用户控件存在于同一个用户控件中。 这个 xml 主页面 ` 我有四个用户控件,我尝试将值从用户控件传递到另一个用户控件,这些用户控件存在于同一个用户控件中。 这个 xml 主页面 ` <Grid> <StackPanel Background="#FFF"> <local:mwidget x:Name="mwidget" Loaded="UserControl1_Loaded"/> <local:addemploy x:Name="addemploy" Visibility="Hidden"/> <local:editemploy x:Name="editemploy" Visibility="Hidden" /> </StackPanel> </Grid>` 还有这个代码 ` private void UserControl1_Loaded(object sender, RoutedEventArgs e) { mwidget.ShowUserControl2Requested += OnShowUserControl2Requested; addemploy.ShowUserControl1Requested += OnShowUserControl1Requested; editemploy.ShowUserControl1Requestedd += ShowUserControl1Requestedd; mwidget.ShowUserControl2Requestedd += ShowUserControl1Requesteddd; } private void OnShowUserControl2Requested(object sender, EventArgs e) { addemploy.Visibility = Visibility.Visible; mwidget.Visibility = Visibility.Collapsed; } private void OnShowUserControl1Requested(object sender, EventArgs e) { mwidget.Visibility = Visibility.Visible; addemploy.Visibility = Visibility.Collapsed; } private void ShowUserControl1Requestedd(object sender, EventArgs e) { mwidget.Visibility = Visibility.Visible; editemploy.Visibility = Visibility.Collapsed; } private void ShowUserControl1Requesteddd(object sender, EventArgs e) { editemploy.Visibility = Visibility.Visible; mwidget.Visibility = Visibility.Collapsed; }` 这个代码mwidget ` public partial class mwidget : UserControl { public event EventHandler ShowUserControl2Requested; public event EventHandler ShowUserControl2Requestedd; public mwidget() { InitializeComponent(); } private void add_employ(object sender, RoutedEventArgs e) { ShowUserControl2Requested?.Invoke(this, EventArgs.Empty); } private void edit_employ(object sender, System.Windows.RoutedEventArgs e) { ShowUserControl2Requestedd?.Invoke(this, EventArgs.Empty); } }` 所以我想将值从 mwidget 传递到 editemploy,我尝试了一些解决方案,但不起作用 您需要在 mwidget 和 editemploy 中创建 DependencyPropertys 并将它们相互绑定。 (注意:在下面的示例中,我使用了 OneWayToSource。这可以防止 editemploy 更改 mwidget 中的值。如果您不想这样做,请将其更改为 TwoWay。) m小部件: public static readonly DependencyProperty MyValueProperty = DependencyProperty.Register( nameof(MyValue), typeof(bool), typeof(mwidget)); public bool MyValue { get => (bool)GetValue(MyValueProperty); set => SetValue(MyValueProperty, value); } 编辑雇佣: public static readonly DependencyProperty MyPassedValueProperty = DependencyProperty.Register( nameof(MyPassedValue), typeof(bool), typeof(editemploy)); public bool MyPassedValue { get => (bool)GetValue(MyPassedValueProperty); set => SetValue(MyPassedValueProperty, value); } xaml: <local:mwidget x:Name="mwidget" Loaded="UserControl1_Loaded"/> <local:addemploy x:Name="addemploy" Visibility="Hidden"/> <local:editemploy x:Name="editemploy" Visibility="Hidden" MyPassedValue="{Binding ElementName=mwidget, Path=MyValue, Mode=OneWayToSource}" />


首次呈现时,使用绑定变量呈现工作表不起作用

我试图在工作表中呈现一个带有 @Binding String 变量的视图,该变量仅在 TextField 中显示/绑定该变量。 在我的主 ContentView 中,我有一个字符串数组,我用


从usercontrol到window的代码behind databind 我有一个问题要问:我正在尝试绑定2个字符串,一个从用户控制到窗口的代码。 这是Usercontrol风格:

这是用户控件的代码文件: using System; using System.Collections.Generic; using System.ComponentModel; using System.Diagnostics; using System.Linq; using System.Runtime.CompilerServices; using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; namespace PasswordManager.Helpers.Resource_UserDefined { public partial class TextBox_Hint : UserControl, INotifyPropertyChanged { public TextBox_Hint() { InitializeComponent(); } public string TextBase { get { return (string)GetValue(TextProperty); } set { SetValue(TextProperty, value); OnPropertyChanged(); } } // Using a DependencyProperty as the backing store for TextBase. This enables animation, styling, binding, etc... public static readonly DependencyProperty TextProperty = DependencyProperty.Register("TextBase", typeof(string), typeof(TextBox_Hint)); public string Hint { get { return (string)GetValue(HintProperty); } set { SetValue(HintProperty, value); } } // Using a DependencyProperty as the backing store for Hint. This enables animation, styling, binding, etc... public static readonly DependencyProperty HintProperty = DependencyProperty.Register("Hint", typeof(string), typeof(TextBox_Hint), new PropertyMetadata("")); public Brush Background { get { return (Brush)GetValue(BackgroundProperty); } set { SetValue(BackgroundProperty, value); } } // Using a DependencyProperty as the backing store for background. This enables animation, styling, binding, etc... public static readonly DependencyProperty BackgroundProperty = DependencyProperty.Register("Background", typeof(Brush), typeof(TextBox_Hint), new PropertyMetadata(Brushes.White)); public Brush BorderColorBrush { get { return (Brush)GetValue(BorderColorBrushProperty); } set { SetValue(BorderColorBrushProperty, value); } } // Using a DependencyProperty as the backing store for BorderColorBrush. This enables animation, styling, binding, etc... public static readonly DependencyProperty BorderColorBrushProperty = DependencyProperty.Register("BorderColorBrush", typeof(Brush), typeof(TextBox_Hint), new PropertyMetadata(Brushes.Black)); public Thickness BorderThickness { get { return (Thickness)GetValue(BorderThicknessProperty); } set { SetValue(BorderThicknessProperty, value); } } // Using a DependencyProperty as the backing store for BorderThickness. This enables animation, styling, binding, etc... public static readonly DependencyProperty BorderThicknessProperty = DependencyProperty.Register("BorderThickness", typeof(Thickness), typeof(TextBox_Hint), new PropertyMetadata(new Thickness(1,1,1,1))); public Brush ForegroundColorOverlay { get { return (Brush)GetValue(ForegroundColorOverlayProperty); } set { SetValue(ForegroundColorOverlayProperty, value); } } // Usando un DependencyProperty come memorizzazione per ForegroundColorOverlay public static readonly DependencyProperty ForegroundColorOverlayProperty = DependencyProperty.Register("ForegroundColorOverlay", typeof(Brush), typeof(TextBox_Hint), new PropertyMetadata(Brushes.Gray)); public FontFamily FontFamily { get { return (FontFamily)GetValue(FontFamilyProperty); } set { SetValue(FontFamilyProperty, value); } } // Using a DependencyProperty as the backing store for FontFamily. This enables animation, styling, binding, etc... public static readonly DependencyProperty FontFamilyProperty = DependencyProperty.Register("FontFamily", typeof(FontFamily), typeof(TextBox_Hint), new PropertyMetadata(new FontFamily("Arial"))); public FontStyle FontStyle { get { return (FontStyle)GetValue(FontStyleProperty); } set { SetValue(FontStyleProperty, value); } } // Using a DependencyProperty as the backing store for FontStyle. This enables animation, styling, binding, etc... public static readonly DependencyProperty FontStyleProperty = DependencyProperty.Register("FontStyle", typeof(FontStyle), typeof(TextBox_Hint), new PropertyMetadata(FontStyles.Normal)); public Double FontSize { get { return (Double)GetValue(FontSizeProperty); } set { SetValue(FontSizeProperty, value); } } // Using a DependencyProperty as the backing store for FontSize. This enables animation, styling, binding, etc... public static readonly DependencyProperty FontSizeProperty = DependencyProperty.Register("FontSize", typeof(Double), typeof(TextBox_Hint), new PropertyMetadata(20.0)); private void txtSearchBox_TextChanged(object sender, TextChangedEventArgs e) { if (string.IsNullOrEmpty(txtSearchBox.Text)) txt_HintBox.Visibility = Visibility.Visible; else txt_HintBox.Visibility = Visibility.Hidden; } public event PropertyChangedEventHandler? PropertyChanged; protected void OnPropertyChanged([CallerMemberName] string propertyName = null) { PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); } } } 我使用这样的用户控件: <userControls:TextBox_Hint x:Name="TextBox_Reame" Height="40" BorderColorBrush="Black" BorderThickness="0,0,0,1" FontFamily="{DynamicResource Abel}" FontSize="20" FontStyle="Italic" ForegroundColorOverlay="Gray" Hint="Inserisci Il Reame" TextBase="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type userControls:TextBox_Hint}}, Path=TextBase}"> <userControls:TextBox_Hint.Background> <LinearGradientBrush StartPoint="0,0" EndPoint="1,0"> <GradientStop Offset="0.0" Color="White" /> <GradientStop Offset="0.5" Color="#FFE1FFE6" /> <GradientStop Offset="1.0" Color="White" /> </LinearGradientBrush> </userControls:TextBox_Hint.Background> </userControls:TextBox_Hint> 这是字符串属性: private string _Reame; public string Reame { get { return _Reame; } set { _Reame = value; OnPropertyChanged(); } } 现在问题开始了。我已经尝试了1000次尝试解决问题,但没有任何回应。我认为我的问题很简单...如何将(用户控件的)文本键值直接获取到我使用的窗口的代码范围内? 如果我使用TextBox_Reame.TextBase,我可以完美地获得值,但是我想使用绑定。我对此窗口的视图模型不感兴趣,因为数据值低。 感谢所有人 我将支持@clemens。我也不完全了解您想做什么,什么对您不起作用。 我将假设您在数据上下文中具有带有“公共字符串reame”属性的ViewModel。 在这种情况下,应将“ textbox_reame.textbase”绑定设置为此属性,而不是自身。 <userControls:TextBox_Hint x:Name="TextBox_Reame" Height="40" BorderColorBrush="Black" BorderThickness="0,0,0,1" FontFamily="{DynamicResource Abel}" FontSize="20" FontStyle="Italic" ForegroundColorOverlay="Gray" Hint="Inserisci Il Reame" TextBase="{Binding Reame}"> <!--TextBase="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type userControls:TextBox_Hint}}, Path=TextBase}">--> <userControls:TextBox_Hint.Background> <LinearGradientBrush StartPoint="0,0" EndPoint="1,0"> <GradientStop Offset="0.0" Color="White" /> <GradientStop Offset="0.5" Color="#FFE1FFE6" /> <GradientStop Offset="1.0" Color="White" /> </LinearGradientBrush> </userControls:TextBox_Hint.Background> </userControls:TextBox_Hint> 我还建议您使用自定义控件而不是UserControl: using System.Windows; using System.Windows.Controls; using System.Windows.Media; namespace SOTopics2025.SO.user27828246.question79511053 { public class TextBox_Hint : TextBox { static TextBox_Hint() { DefaultStyleKeyProperty.OverrideMetadata(typeof(TextBox_Hint), new FrameworkPropertyMetadata(typeof(TextBox_Hint))); } public string Hint { get => (string)GetValue(HintProperty); set => SetValue(HintProperty, value); } // Using a DependencyProperty as the backing store for Hint. This enables animation, styling, binding, etc... public static readonly DependencyProperty HintProperty = DependencyProperty.Register(nameof(Hint), typeof(string), typeof(TextBox_Hint), new PropertyMetadata(string.Empty)); public Brush HintForeground { get => (Brush)GetValue(HintForegroundProperty); set => SetValue(HintForegroundProperty, value); } // Usando un DependencyProperty come memorizzazione per ForegroundColorOverlay public static readonly DependencyProperty HintForegroundProperty = DependencyProperty.Register(nameof(HintForeground), typeof(Brush), typeof(TextBox_Hint), new PropertyMetadata(Brushes.Gray)); public Visibility HintVisibility { get => (Visibility)GetValue(HintVisibilityProperty); private set => SetValue(HintVisibilityPropertyKey, value); } // Using a DependencyProperty as the backing store for Hint. This enables animation, styling, binding, etc... public static readonly DependencyPropertyKey HintVisibilityPropertyKey = DependencyProperty.RegisterReadOnly(nameof(HintVisibility), typeof(Visibility), typeof(TextBox_Hint), new PropertyMetadata(Visibility.Visible)); public static readonly DependencyProperty HintVisibilityProperty = HintVisibilityPropertyKey.DependencyProperty; protected override void OnTextChanged(TextChangedEventArgs e) { base.OnTextChanged(e); HintVisibility = string.IsNullOrEmpty(Text) ? Visibility.Visible : Visibility.Collapsed; } } } themes/generic.xaml: <SolidColorBrush x:Key="TextBox_Hint.Static.Border" Color="#FFABAdB3"/> <SolidColorBrush x:Key="TextBox_Hint.MouseOver.Border" Color="#FF7EB4EA"/> <SolidColorBrush x:Key="TextBox_Hint.Focus.Border" Color="#FF569DE5"/> <Style TargetType="{x:Type custcont:TextBox_Hint}"> <Setter Property="Background" Value="{DynamicResource {x:Static SystemColors.WindowBrushKey}}"/> <Setter Property="BorderBrush" Value="{StaticResource TextBox_Hint.Static.Border}"/> <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/> <Setter Property="BorderThickness" Value="1"/> <Setter Property="KeyboardNavigation.TabNavigation" Value="None"/> <Setter Property="HorizontalContentAlignment" Value="Left"/> <Setter Property="FocusVisualStyle" Value="{x:Null}"/> <Setter Property="AllowDrop" Value="true"/> <Setter Property="ScrollViewer.PanningMode" Value="VerticalFirst"/> <Setter Property="Stylus.IsFlicksEnabled" Value="False"/> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type custcont:TextBox_Hint}"> <Border x:Name="border" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" SnapsToDevicePixels="True"> <Grid> <ScrollViewer x:Name="PART_ContentHost" Focusable="false" HorizontalScrollBarVisibility="Hidden" VerticalScrollBarVisibility="Hidden"/> <TextBlock x:Name="Hint_text" Text="{TemplateBinding Hint}" Foreground="{TemplateBinding HintForeground}" Visibility="{TemplateBinding HintVisibility}" IsHitTestVisible="False"/> </Grid> </Border> <ControlTemplate.Triggers> <Trigger Property="IsEnabled" Value="false"> <Setter Property="Opacity" TargetName="border" Value="0.56"/> </Trigger> <Trigger Property="IsMouseOver" Value="true"> <Setter Property="BorderBrush" TargetName="border" Value="{StaticResource TextBox_Hint.MouseOver.Border}"/> </Trigger> <Trigger Property="IsKeyboardFocused" Value="true"> <Setter Property="BorderBrush" TargetName="border" Value="{StaticResource TextBox_Hint.Focus.Border}"/> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> </Setter.Value> </Setter> <Style.Triggers> <MultiTrigger> <MultiTrigger.Conditions> <Condition Property="IsInactiveSelectionHighlightEnabled" Value="true"/> <Condition Property="IsSelectionActive" Value="false"/> </MultiTrigger.Conditions> <Setter Property="SelectionBrush" Value="{DynamicResource {x:Static SystemColors.InactiveSelectionHighlightBrushKey}}"/> </MultiTrigger> </Style.Triggers> </Style> usage: <StackPanel> <FrameworkElement.DataContext> <local:SomeViewModel Reame="Some text"/> </FrameworkElement.DataContext> <local:TextBox_Hint Hint="Inserisci Il Reame" Text="{Binding Reame, UpdateSourceTrigger=PropertyChanged}" Margin="10"/> <TextBlock Text="{Binding Reame}"/> </StackPanel>



如何查找给定的键是否存在于 std::map 中

我正在尝试检查给定的键是否在地图中,但有些无法做到: typedef 映射::迭代器 mi; 地图米; m.insert(make_pair("f","++--")); 一对 我正在尝试检查给定的键是否在地图中,但有些做不到: typedef map<string,string>::iterator mi; map<string, string> m; m.insert(make_pair("f","++--")); pair<mi,mi> p = m.equal_range("f");//I'm not sure if equal_range does what I want cout << p.first;//I'm getting error here 那么我怎样才能打印p中的内容呢? 使用 map::find 和 map::end: if (m.find("f") == m.end()) { // not found } else { // found } 要检查映射中是否存在特定键,请通过以下方式之一使用 count 成员函数: m.count(key) > 0 m.count(key) == 1 m.count(key) != 0 map::find的文档说:“另一个成员函数map::count可用于仅检查特定键是否存在。” map::count的文档说:“因为地图容器中的所有元素都是唯一的,所以该函数只能返回1(如果找到该元素)或零(否则)。” 要通过您知道存在的键从映射中检索值,请使用 map::at: value = m.at(key) 与 map::operator[] 不同,如果指定的键不存在,map::at 不会在映射中创建新键。 C++20 为我们提供了 std::map::contains 来做到这一点。 #include <iostream> #include <string> #include <map> int main() { std::map<int, std::string> example = {{1, "One"}, {2, "Two"}, {3, "Three"}, {42, "Don\'t Panic!!!"}}; if(example.contains(42)) { std::cout << "Found\n"; } else { std::cout << "Not found\n"; } } 您可以使用.find(): map<string,string>::iterator i = m.find("f"); if (i == m.end()) { /* Not found */ } else { /* Found, i->first is f, i->second is ++-- */ } C++17 通过带有初始化器的 If 语句进一步简化了这一点。 这样你就可以鱼与熊掌兼得了。 if ( auto it{ m.find( "key" ) }; it != std::end( m ) ) { // Use `structured binding` to get the key // and value. const auto&[ key, value ] { *it }; // Grab either the key or value stored in the pair. // The key is stored in the 'first' variable and // the 'value' is stored in the second. const auto& mkey{ it->first }; const auto& mvalue{ it->second }; // That or just grab the entire pair pointed // to by the iterator. const auto& pair{ *it }; } else { // Key was not found.. } m.find == m.end() // not found 如果您想使用其他API,请找到m.count(c)>0 if (m.count("f")>0) cout << " is an element of m.\n"; else cout << " is not an element of m.\n"; 我想你想要map::find。如果 m.find("f") 等于 m.end(),则未找到密钥。否则,find 返回一个指向找到的元素的迭代器。 错误是因为p.first是一个迭代器,它不适用于流插入。将最后一行更改为 cout << (p.first)->first;。 p 是一对迭代器,p.first 是迭代器,p.first->first 是键字符串。 一张地图对于给定的键只能有一个元素,所以 equal_range 不是很有用。它是为映射定义的,因为它是为所有关联容器定义的,但它对于多重映射更有趣。 template <typename T, typename Key> bool key_exists(const T& container, const Key& key) { return (container.find(key) != std::end(container)); } 当然,如果你想变得更奇特,你可以随时模板化一个函数,该函数也采用已找到的函数和未找到的函数,如下所示: template <typename T, typename Key, typename FoundFunction, typename NotFoundFunction> void find_and_execute(const T& container, const Key& key, FoundFunction found_function, NotFoundFunction not_found_function) { auto& it = container.find(key); if (it != std::end(container)) { found_function(key, it->second); } else { not_found_function(key); } } 并像这样使用它: std::map<int, int> some_map; find_and_execute(some_map, 1, [](int key, int value){ std::cout << "key " << key << " found, value: " << value << std::endl; }, [](int key){ std::cout << "key " << key << " not found" << std::endl; }); 这样做的缺点是想出一个好名字,“find_and_execute”很尴尬,我想不出更好的名字...... map<string, string> m; 检查 key 是否存在,并返回出现次数(map 中为 0/1): int num = m.count("f"); if (num>0) { //found } else { // not found } 检查key是否存在,并返回迭代器: map<string,string>::iterator mi = m.find("f"); if(mi != m.end()) { //found //do something to mi. } else { // not found } 在你的问题中,由坏的operator<<过载引起的错误,因为p.first是map<string, string>,你无法打印出来。尝试这个: if(p.first != p.second) { cout << p.first->first << " " << p.first->second << endl; } 小心地将查找结果与地图“m”的结尾进行比较,因为所有答案都有 上面完成 地图::迭代器 i = m.find("f"); if (i == m.end()) { } else { } 您不应该尝试执行任何操作,例如如果迭代器 i 等于 m.end() 则打印键或值,否则会导致分段错误。 比较 std::map::find 和 std::map::count 的代码,我认为第一个可能会产生一些性能优势: const_iterator find(const key_type& _Keyval) const { // find an element in nonmutable sequence that matches _Keyval const_iterator _Where = lower_bound(_Keyval); // Here one looks only for lower bound return (_Where == end() || _DEBUG_LT_PRED(this->_Getcomp(), _Keyval, this->_Key(_Where._Mynode())) ? end() : _Where); } size_type count(const key_type& _Keyval) const { // count all elements that match _Keyval _Paircc _Ans = equal_range(_Keyval); // Here both lower and upper bounds are to be found, which is presumably slower. size_type _Num = 0; _Distance(_Ans.first, _Ans.second, _Num); return (_Num); } find() 和 contains() 都可以使用。根据文档。两种方法平均时间为常数,最坏情况下为线性时间。 我知道这个问题已经有一些很好的答案,但我认为我的解决方案值得分享。 它适用于 std::map 和 std::vector<std::pair<T, U>>,并且可从 C++11 开始使用。 template <typename ForwardIterator, typename Key> bool contains_key(ForwardIterator first, ForwardIterator last, Key const key) { using ValueType = typename std::iterator_traits<ForwardIterator>::value_type; auto search_result = std::find_if( first, last, [&key](ValueType const& item) { return item.first == key; } ); if (search_result == last) { return false; } else { return true; } } map <int , char>::iterator itr; for(itr = MyMap.begin() ; itr!= MyMap.end() ; itr++) { if (itr->second == 'c') { cout<<itr->first<<endl; } } 如果你想比较成对的地图,你可以使用这个方法: typedef map<double, double> TestMap; TestMap testMap; pair<map<double,double>::iterator,bool> controlMapValues; controlMapValues= testMap.insert(std::pair<double,double>(x,y)); if (controlMapValues.second == false ) { TestMap::iterator it; it = testMap.find(x); if (it->second == y) { cout<<"Given value is already exist in Map"<<endl; } } 这是一项有用的技术。


各组之间的差异

我有一个像这样的数据框: df = 数据.frame( 重复 = c(1,1,1,2,2,2), 组 = c("a", "b", "c", "a", "b", "c"), 分辨率 = c(10,8,9...


在另一个列表中计算一个列表中的元素

df 是这样的: df <- data.frame( groups=I(list(c("a"), c("b","c", "d", "e","f"), c("g","h"), c("i&quo...




.NET MAUI:自定义Shell TitleView并绑定到当前页面标题

我想用我自己的自定义布局替换默认的 Shell 标头,如下所示: 我想用我自己的自定义布局替换默认的 Shell 标头,如下所示: <?xml version="1.0" encoding="UTF-8" ?> <Shell x:Class="MyNamespace.App.AppShell" xmlns="http://schemas.microsoft.com/dotnet/2021/maui" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:local="clr-namespace:MyNamespace.App" xmlns:pages="clr-namespace:MyNamespace.App.Pages" BindingContext="{x:Static local:MainView.Instance}" Shell.FlyoutBehavior="{Binding ShellFlyoutType}" x:Name="shellMain"> <Shell.TitleView> <Grid ColumnDefinitions="*,200"> <Label BindingContext="{x:Reference shellMain}" Text="{Binding Path=CurrentPage.Title, Mode=OneWay}" FontSize="Large" TextColor="White" /> <ActivityIndicator IsRunning="{Binding IsBusy}" Color="Orange" Grid.Column="1" HorizontalOptions="End" /> </Grid> </Shell.TitleView> <ShellContent Title=" Login" ContentTemplate="{DataTemplate local:MainPage}" Route="login" FlyoutItemIsVisible="False" /> <ShellContent Title="Dashboard" ContentTemplate="{DataTemplate pages:DashboardPage}" Route="dashboard" /> </Shell> 我无法绑定当前页面标题。 我的 AppShell.xaml Shell 声明如下 <Shell ... x:Name="shellMain"> 作为替代方案,您可以在 OnNaviged 方法中设置 titleview : 在 AppShell.xaml 中,定义标签的名称 <Shell.TitleView> <Grid ColumnDefinitions="*,200"> <Label BindingContext="{x:Reference shellMain}" x:Name="mylabel" FontSize="Large" TextColor="White" /> <ActivityIndicator IsRunning="{Binding IsBusy}" Color="Orange" Grid.Column="1" HorizontalOptions="End" /> </Grid> </Shell.TitleView> 在AppShell.xaml.cs中,重写OnNaviged方法,获取当前项目 protected override void OnNavigated(ShellNavigatedEventArgs args) { base.OnNavigated(args); var shellItem = Shell.Current?.CurrentItem; string title = shellItem?.Title; int iterationCount = 0; while (shellItem != null && title == null) { title = shellItem.Title; shellItem = shellItem.CurrentItem; if (iterationCount > 10) break; // max nesting reached iterationCount++; } myLabel.Text = title; } 希望它对你有用。 我正在尝试同样的方法来修改 TitleView 的外观。它可以在 iOS 上运行,尽管那里还有另一个错误。但在 Android 上我遇到了同样的问题。在前进导航中,它会更新标题,但当您按后退按钮时,标题不会更新。我已经打开了一个问题并添加了一个存储库。 https://github.com/dotnet/maui/issues/12416#issuecomment-1372627514 还有其他方法可以修改TitleView的外观吗? 我使用视图模型开发了这个解决方法,主要不是为了提供 MVVM 解决方案,而是因为其他建议的答案对我不起作用。 (我怀疑 Liqun Shen 2 月 15 日针对他自己的问题的评论中的建议会起作用。但我没有注意到这一点,直到我自己修复)。 当前页面的标题保存在可由 shell 的视图模型和每个内容页面的视图模型访问的类中: public class ServiceHelper { private static ServiceHelper? _default; public static ServiceHelper Default => _default ??= new ServiceHelper(); internal string CurrentPageTitle { get; set; } = string.Empty; } shell 中每个内容页面的视图模型提供其页面标题。为了促进这一点,大部分工作都是由基本视图模型完成的,它们都是从该模型派生而来的: public abstract class ViewModelBase(string title) : ObservableObject { private ServiceHelper? _serviceHelper; public string Title { get; } = title; internal ServiceHelper ServiceHelper { get => _serviceHelper ??= ServiceHelper.Default; set => _serviceHelper = value; // For unit testing. } public virtual void OnAppearing() { ServiceHelper.CurrentPageTitle = Title; } } 每个 shell 内容页面视图模型只需要让其基础视图模型知道它的标题: public class LocationsViewModel : ViewModelBase { public LocationsViewModel() : base("Locations") { } } 每个 shell 内容页面都需要在其视图模型中触发所需的事件响应方法: public partial class LocationsPage : ContentPage { private LocationsViewModel? _viewModel; public LocationsPage() { InitializeComponent(); } private LocationsViewModel ViewModel => _viewModel ??= (LocationsViewModel)BindingContext; protected override void OnAppearing() { base.OnAppearing(); ViewModel.OnAppearing(); } } Shell 的视图模型为标题栏提供当前页面的标题: public class AppShellViewModel() : ViewModelBase(Global.ApplicationTitle) { private string _currentPageTitle = string.Empty; public string CurrentPageTitle { get => _currentPageTitle; set { _currentPageTitle = value; OnPropertyChanged(); } } public void OnNavigated() { CurrentPageTitle = ServiceHelper.CurrentPageTitle; } } Shell 需要在其视图模型中触发所需的事件响应方法: public partial class AppShell : Shell { private AppShellViewModel? _viewModel; public AppShell() { InitializeComponent(); } private AppShellViewModel ViewModel => _viewModel ??= (AppShellViewModel)BindingContext; protected override void OnNavigated(ShellNavigatedEventArgs args) { base.OnNavigated(args); ViewModel.OnNavigated(); } } 最后,Shell 的 XAML 在标题栏/导航栏上显示由 Shell 视图模型提供的当前页面的标题: <Shell.TitleView> <HorizontalStackLayout VerticalOptions="Fill"> <Image Source="falcon_svg_repo_com.png" HeightRequest="50"/> <Label x:Name="CurrentPageTitleLabel" Text="{Binding CurrentPageTitle}" FontSize="24" Margin="10,0" VerticalTextAlignment="Center"/> </HorizontalStackLayout> </Shell.TitleView>


活动深层链接 - IllegalArgumentException:缺少必需的参数并且没有 android:defaultValue

在我的应用程序中,我有以下结构: 在我的应用程序中,我具有以下结构: <!-- AndroidManifest.xml --> <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android"> <application> <activity android:name=".DeepLinkActivity" android:exported="true" android:launchMode="singleInstancePerTask"> <intent-filter> <action android:name="android.intent.action.VIEW" /> <category android:name="android.intent.category.DEFAULT" /> <category android:name="android.intent.category.BROWSABLE" /> <data android:host="myhost" android:path="/mypath" android:scheme="myscheme" /> </intent-filter> </activity> </application> </manifest> <!-- activity_deep_link.xml --> <?xml version="1.0" encoding="utf-8"?> <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent"> <androidx.fragment.app.FragmentContainerView android:id="@+id/navHostFragment" android:name="androidx.navigation.fragment.NavHostFragment" android:layout_width="match_parent" android:layout_height="match_parent" app:defaultNavHost="true" tools:navGraph="@navigation/my_nav_graph" /> </FrameLayout> // DeepLinkActivity.kt class DeepLinkActivity : AppCompatActivity() { private lateinit var binding: ActivityDeepLinkBinding override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) binding = ActivityDeepLinkBinding.inflate(layoutInflater) setContentView(binding.root) setUpNavigationGraph() } private fun setUpNavigationGraph() { val navHostFragment = supportFragmentManager .findFragmentById(binding.navHostFragment.id) as NavHostFragment val navController = navHostFragment.navController val navGraph = navController.navInflater .inflate(R.navigation.my_nav_graph) .apply { this.setStartDestination(R.id.notTheStartDestinationFragment) } val startDestinationArgs = bundleOf( "someRequiredArgumentHere" to false ) navController.setGraph(navGraph, startDestinationArgs) } } 当我通过 ADB (adb shell am start -d myscheme://myhost/mypath) 通过深度链接打开该活动时,该活动正常启动。 但是当我通过 Chrome 应用程序启动它时,应用程序崩溃了: 原因:java.lang.IllegalArgumentException:缺少必需参数“someRequiredArgumentHere”并且没有 android:defaultValue 观察:我正在使用 Safe Args 插件。 我做错了什么以及为什么行为不同? 我刚刚发现为什么在通过浏览器导航时会忽略 startDestinationArgs。 如果我们检查NavController#setGraph(NavGraph, Bundle?)的内部代码,如果没有发生深层链接,NavController#onGraphCreated(Bundle?)只会使用startDestinationArgs。 作为一种解决方法,在设置导航图之前,我只需清除活动的意图(但这可能不是解决该问题的最佳方法)


用逗号分割字符串,并删除一些字符

以下是我想要分离的值: <- data.frame(x = c("c(58663.809, 232648.355, 0)", "c(5902.873, 232674.248, 0)")) I would like to remove the "c(",


从 C# 访问 C 全局变量 'errno'

P/Invoking 时是否可以访问 C# 中的“errno”变量?这类似于 Win32 GetLastError()。


F# 从 while 循环中中断

有什么办法可以像C/C#那样做到吗? 例如(C#风格) 对于 (int i = 0; i < 100; i++) { if (i == 66) break; }


为什么 GetDirectoryName 对 C:\ 返回 null?

我刚刚遇到了一个看起来很奇怪的设计选择: System.IO.Path.GetDirectoryName(@"C: 旧的 ile.ext") 返回“C:较旧” 但 System.IO.Path.GetDirectoryName(@"C:\") 返回空值。 我




首次查找连续两个相同值的索引

我有一个相当简短的问题。 这些是一些要重现的示例向量: 一个<- c(14,26,38,64,96,127,152,152,152,152,152,152) b <- c(4,7,9,13,13,13,13,13,13,13,13,13,13,13) c <- c(62,...


C++ 代码链接中的错误:警告 C4190:类型已指定 C 链接,但返回与 C 不兼容的 UDT

我很难理解为什么以下代码(具有标准布局的 UDT)在 Visual C++ 2012 中给出 C 链接警告: 警告 C4190:“vec3_add”已指定 C 链接,但返回...


删除列表中奇数长度的元素

我有一个列表,我想删除具有奇数长度的元素: 我的列表<- list() my_list$a <- c(1,2,3,4) #length 4 my_list$b <- c(1,2,3) # length 3 my_list$c <- c(5,6,7,8,6,7) #



协调 C++ 和 Objective-C 中结构的填充

我使用 Objective-C 和 Metal 渲染到窗口,但是我的所有应用程序代码都是用 C++ 编写的。因此,CPU 对 MTLBuffer 内数据的所有操作都是用 C++ 完成的。这是由


Displayalert 未显示在 IOS .net Maui 的 MopupServices 弹出页面上

下面的代码没有在 iOS 的弹出页面上显示显示警报。 在android中它可以正常工作。 我正在使用 Mopups.Pages.PopupPage 我正在使用 mvvm。 下面的代码没有在 iOS 的弹出页面上显示显示警报。 在android中它可以正常工作。 我正在使用Mopups.Pages.PopupPage 我正在使用 mvvm。 <?xml version="1.0" encoding="utf-8" ?> <pages:PopupPage xmlns:pages="clr-namespace:Mopups.Pages;assembly=Mopups" xmlns="http://schemas.microsoft.com/dotnet/2021/maui" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:animations="clr-namespace:Mopups.Animations;assembly=Mopups" xmlns:ffimage="clr-namespace:FFImageLoading.Maui;assembly=FFImageLoading.Maui" xmlns:FFImgLoad="clr-namespace:FFImageLoading.Maui;assembly=FFImageLoading.Maui" x:Class="Gaibo.Pages.CostPopupPage" BackgroundColor="#80000000" > <pages:PopupPage.Animation> <animations:ScaleAnimation PositionIn="Center" PositionOut="Center" ScaleIn=".7" ScaleOut="0.7" EasingIn="Linear"/> </pages:PopupPage.Animation> <StackLayout HorizontalOptions="CenterAndExpand" Margin="10" VerticalOptions="CenterAndExpand"> <Button Grid.Row="3" CornerRadius="20" Padding="0" Text="Submit" VerticalOptions="CenterAndExpand" HeightRequest="45" Style="{StaticResource AllSubmitBtnStyle}" Command="{Binding SubmitCostCommand}"/> </StackLayout> </pages:PopupPage> SubmitCostCommand 命令的代码 public class CampaignDetailsViewModel { private async Task SubmitCostCommandClicked() { await App.Current.MainPage.DisplayAlert("", " Thank you for submitting Post Social Link/s.", "Ok"); } } 在cs文件中 public CostPopupPage (CampaignDetailslstData CampaignData) { InitializeComponent(); var vm = new CampaignDetailsViewModel(); } 这是 Mopups 的已知问题。为了在 mopup 顶部显示警报,您需要从 mopup 页面本身而不是主页调用警报。 private async Task SubmitCostCommandClicked() { var topPage = Mopups.Services.MopupService.Instance.PopupStack[^1]; await topPage.DisplayAlert("Confirm", "Are you sure you want to cancel?", "Yes", "No") }


在一列中搜索多个关键字并为每个关键字创建列

我有以下数据。 搜索字符串 <- c("to", "and", "at", "from", "is", "of") set.seed(199) id <- c(rnorm(5)) x <- c(...


使用嵌套列表在 Python 中创建嵌套字典

我有三个清单: A = ['a','b','c'] B = [[1,2,3],[4,5,6]] 和 C = ['A','B'] 我需要创建一个具有以下特征的字典: {'A':{'a':1, 'b':2, 'c':3}, 'B':{'a':4, 'b':5, 'c'...


针对经验丰富的 C 程序员的 C++ 教程 [已关闭]

我已经用 C 语言编程 25 年了,但从未使用过 C++。我现在需要学习 C++ 编程的基础知识。任何人都可以推荐在线教程(或者失败的书)


根据预定义范围计算列的行和

我有一个与此类似的数据集: 数据集<- structure( list( Participant.Id = 1:5, x1 = c(10L, 20L, 30L, 40L, 50L), x2 = c(15L, 25L, 35L, 45L, 55L), x3 = c(20L, 25L, NA, 45L, NA), x4 = c(25L...


如何使用 OpenCL C++ API 获取设备 cl_device_id

我开始使用 OpenCL C++ API。我已经使用 C API 很长时间了。 C++ API 更加优雅、简单,代码更少且不易出错,但我需要设备 ID。我...


非数组的 C 花括号初始化器

请考虑以下荒谬但编译的代码: int main(int argc, char *argv[]) { 无效*a,*b,*c,*d; void *the_good_array[] = { a, b, c, d }; void *the_bad_array = { a, ...


在C#中运行C++ dll来调用函数

我有 C++ 代码,我想将其打包为 dll 并在 C# 代码中使用。我制作了 dll,但是当我加载它时,我收到 System.AccessViolationException。 (首先,dll 无法加载,之后...


DolphinDB:在SQL语句中使用动态函数时出错

以下是我的脚本: sym = `C`MS`MS`MS`IBM`IBM`C`C`C$SYMBOL 价格= 49.6 29.46 29.52 30.02 174.97 175.23 50.76 50.32 51.29 数量 = 2200 1900 2100 3200 6800 5400 1300 2500 8800 时间戳 = [09:3...


类方法中的 Arduino C++ 回调

我是 Arduino 和 C++ 的新手,我对 arduino (c++)、类和类方法中的“this”有疑问: 我创建 classname.cpp 和 classname.h 在 classname.cpp 中,我尝试获取“this”(


如何只保留唯一的行而忽略列?

如果我有这些数据: df1 <- data.frame(name = c("apple", "apple", "apple", "orange", "orange"), ID = c(1, 2, 3, 4, 5), is_fruit = c("yes", "yes", "yes", "yes", "yes")) and I want...


如何系统地根据列位置对列进行操作?

有没有一种方法可以根据列的位置系统地划分列? 例如,使用这样的数据框: df <- data.frame(id = ('a1', 'a2'), a = c(1, 0), b = c(4,0), c = c(4, 3...


最新问题
© www.soinside.com 2019 - 2025. All rights reserved.