binding 相关问题

这个标签在不同的环境中意味着不同的东西;考虑使用较少模糊的标签来代替或另外。常见含义包括:依赖项注入和数据绑定到对象和应用程序组件之间的绑定。

在 Xamarin 中绑定 AAR 时删除样式属性

有没有办法在绑定 AAR 时删除对样式属性的引用?我的 AAR 在构建项目时会抛出错误,因为生成的 DLL 正在引用我的项目的样式属性...

回答 1 投票 0

在 WinUI 3 中的样式设置器中进行绑定

WinUI 3 是否支持样式设置器中的绑定?我已经为 NavigationView 定义了样式,第三行是: WinUI 3 支持样式设置器中的绑定吗?我已经为 NavigationView 定义了样式,第三行是: <Setter Property="CompactPaneLength" Value="{Binding CurrentCompactPaneLength}" /> 这会在运行时产生 Specified cast is not valid. 异常。包含 NavigationView 的页面的 DataContext 是该页面的 ViewModel。 NavigationView.CompactPaneLength 和 CurrentCompactPaneLength 都是 double 和 public,并且 CurrentCompactPaneLength 是一个 ObservableObject(来自 CommunityToolkit.Mvvm.ComponentModel)。 WinUI 3 (SDK 1.1.2) 的源代码包含各种 Setter,例如 <Setter Target="PaneContentGrid.Width" Value="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=CompactPaneLength}" /> 如果有必要的话,在代码中进行绑定是可行的。但 XAML 不应该也起作用吗? 显然,WinUI 3 尚不支持 Setter 中的常规绑定,尽管这是一项备受期待的功能。解决方法是创建一个包含 DependencyProperty 的帮助程序类,每当更改/设置属性时,该类都会调用更改处理程序。然后,更改处理程序可以在代码中创建所需的绑定。感谢 clemens,他很久以前就为 UWP 提出了类似的建议。这是一个辅助类示例: internal class BindingHelper { #region CompactPaneLengthBindingPath public static readonly DependencyProperty CompactPaneLengthBindingPathProperty = DependencyProperty.RegisterAttached( "CompactPaneLengthBindingPath", typeof(string), typeof(BindingHelper), new PropertyMetadata(null, BindingPathChanged)); public static string GetCompactPaneLengthBindingPath(DependencyObject obj) { return (string)obj.GetValue(CompactPaneLengthBindingPathProperty); } public static void SetCompactPaneLengthBindingPath(DependencyObject obj, string value) { obj.SetValue(CompactPaneLengthBindingPathProperty, value); } #endregion #region HeightBindingPath // another DP is defined here (all of them are strings) #region ForegroundBindingPath // and a third one, etc. // ===================== Change Handler: Creates the actual binding private static void BindingPathChanged(DependencyObject obj, DependencyPropertyChangedEventArgs e) { if (e.NewValue is string source) // source property (could add DataContext by setting Value="source@datacontext" for example) { DependencyProperty target; // which property is the target of the binding? if (e.Property == CompactPaneLengthBindingPathProperty) target = NavigationView.CompactPaneLengthProperty; else if (e.Property == HeightBindingPathProperty) target = FrameworkElement.HeightProperty; else if (e.Property == ForegroundBindingPathProperty) target = Control.ForegroundProperty; else throw new System.Exception($"BindingHelper: Unknown target ({nameof(e.Property)}"); // don't know this property obj.ClearValue(target); // clear previous bindings (and value) BindingOperations.SetBinding(obj, target, // set new binding (and value) new Binding { Path = new PropertyPath(source), Mode = BindingMode.OneWay }); } } 请注意,所有 DependencyProperties 都是字符串类型,并且目标类型可以是您正在使用的控件的任何祖先类型。例如,HeightBindingPathProperty 绑定可以与任何 FrameworkElement 一起使用。 在 Style 中使用 helper 就像使用任何 Setter 一样,如下所示: <Style x:Key="MyNavigationView" TargetType="controls:NavigationView" > <Setter Property="local:BindingHelper.CompactPaneLengthBindingPath" Value="CurrentCompactPaneLength" /> </Style> 我希望这有帮助。 这对我有用: <Page.Resources> <Style TargetType="TextBlock"> <Setter Property="FontSize" Value="{x:Bind ViewModel.FontSize, Mode=OneWay}" /> </Style> </Page.Resources>

回答 2 投票 0

如何在不同的项目maui c#中绑定对象

有谁知道如何将对象绑定到不同的项目? 例如我有2个项目。一个是我的 maui 应用程序,其中包含 Mainpage.xaml,另一个是我想重用的 dll

回答 1 投票 0

在通知属性更改而不将新实例分配给属性时,Wpf 绑定不起作用

所以,我有这个非常简单的代码,当我在使用注释的代码行时单击按钮时,GUI 中的值通过绑定更新,一切正常。如果我使用另外两条线...

回答 1 投票 0

在日期输入元素(html 日期选择器)中将纪元日期时间显示为格式化日期

有角度 想要在日期输入元素(html日期选择器)中将纪元日期时间显示为格式化日期,使用绑定在输入中显示 我可以通过使用函数并在输入中设置来显示这一点,但想要...

回答 1 投票 0

在 Swift UI 中使用 TextFiled 同时更新两条记录

我使用文本文件,我可以在其中输入产品的数量。我正在使用 $Binding 属性包装器。这是购物车视图(订单视图)。问题是当我输入值时它会更新 b...

回答 1 投票 0

数据上下文冲突

<UserControl x:Class="WatermarkTextBox" 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" mc:Ignorable="d" d:DesignHeight="30" d:DesignWidth="250"> <UserControl.Resources> <BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter" /> </UserControl.Resources> <Border> <Grid x:Name="grid"> <TextBlock Text="{Binding Watermark, FallbackValue=This prompt dissappears as you type...}" Visibility="{Binding ElementName=txtUserEntry, Path=Text.IsEmpty, Converter={StaticResource BooleanToVisibilityConverter}}" /> <TextBox Name="txtUserEntry" Text="{Binding Text, UpdateSourceTrigger=PropertyChanged}" /> </Grid> </Border> </UserControl> 上面的代码显示了我的 WatermarkTextBox 控件。在文件后面的代码中,我设置了 DataContext。我省略了控件 DP 的所有代码。 public WatermarkTextBox() { InitializeComponent(); grid.DataContext = this; } 我必须将 DataContext 绑定到网格,否则水印和实际文本的 Text 属性将不会显示。现在的问题是我无法将Background的Border设置在Grid之外。 我尝试了下面的代码,但只设置了 Background 的 Border,而不是水印和实际文本。 public WatermarkTextBox() { InitializeComponent(); this.DataContext = this; grid.DataContext = this; } 在这样的 UserControl 中,您永远不应该将 DataContext 显式设置为 this 或其他任何值,因为当您在应用程序中的某个位置使用 UserControl 时,DataContext 通常是在外部设置的。外部应用的 DataContext 通常是应用程序视图模型(的一部分)。 您应该更改内部绑定,以便它们使用显式 RelativeSource: <TextBlock Text="{Binding Path=Watermark, RelativeSource={RelativeSource AncestorType=UserControl}, FallbackValue=This prompt dissappears as you type...}" Visibility="{Binding ElementName=txtUserEntry, Path=Text.IsEmpty, Converter={StaticResource BooleanToVisibilityConverter}}" /> <TextBox Name="txtUserEntry" Text="{Binding Path=Text, UpdateSourceTrigger=PropertyChanged, RelativeSource={RelativeSource AncestorType=UserControl}}" /> 然后从 UserControl 的构造函数中删除任何 DataContext 赋值。 参见例如这个答案(以及许多其他类似的答案)详细讨论了这个主题。 @Clemens 答案的附录: 为了避免为每个控件设置 RelativeSource={RelativeSource AncestorType=UserControl},请在用户控件中提供一个根元素来获取 DataContext。 <UserControl x:Class="UserControlBindingIssue.TestUserControl" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:local="clr-namespace:UserControlBindingIssue" d:DataContext="{d:DesignInstance Type=local:TestUserControl, IsDesignTimeCreatable=True}" mc:Ignorable="d"> <ContentControl DataContext="{Binding RelativeSource={RelativeSource AncestorType={x:Type local:TestUserControl}}}"> <TextBox Width="100" Text="{Binding Text, UpdateSourceTrigger=PropertyChanged}" /> <!-- Other controls --> </ContentControl> </UserControl>

回答 2 投票 0

Pythonnet - 内存管理错误

环境 Pythonnet版本:3.0.2 Python版本:3.9 操作系统:Windows 10 .NET 运行时:.NET Framework 4.8 细节 我正在尝试通过 .NET Framework DLL 打开一个大文件并...

回答 1 投票 0

XAML 中的绑定中是否可以仅包含边距的一部分

我有一个XAML,包含如下信息: ...保证金=“10,20,30,40”... 我知道在绑定中设置左边距非常容易,如下所示: Margin="{绑定margin_value...

回答 1 投票 0

MAUI CollectionView 中的绑定字符串问题

我创建了一个名为SectionTitle 的.net MAUI 组件,它有两个属性:一个用于背景颜色,一个用于标签字符串。 我创建了一个名为 SectionTitle 的 .net MAUI 组件,它有两个属性:一个用于背景颜色,一个用于标签字符串。 <?xml version="1.0" encoding="utf-8" ?> <ContentView x:Class="mater.Components.SectionTitle" xmlns="http://schemas.microsoft.com/dotnet/2021/maui" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:c="clr-namespace:mater.Components" x:DataType="c:SectionTitle"> <Grid ColumnDefinitions="3*,2*"> <Grid ColumnDefinitions="Auto,*"> <Border x:Name="Bordo" Grid.Column="0" Padding="5,10,20,10" Background="{Binding BGColor}" StrokeShape="RoundRectangle 0,10,0,10"> <Label x:Name="Lbl" Grid.Column="0" Text="{Binding LabelText}" /> </Border> </Grid> </Grid> </ContentView> 对应的c#代码如下: namespace mater.Components; public partial class SectionTitle : ContentView { public static readonly BindableProperty BGColorProperty = BindableProperty.Create( nameof(BGColor), typeof(Brush), typeof(SectionTitle), default(Brush)); public static readonly BindableProperty LabelTextProperty = BindableProperty.Create( nameof(LabelText), typeof(string), typeof(SectionTitle), ""); public Brush BGColor { get { return (Brush)GetValue(BGColorProperty); } set { SetValue(BGColorProperty, value); } } public string LabelText { get { return (string)GetValue(LabelTextProperty); } set { SetValue(LabelTextProperty, value); } } public SectionTitle() { InitializeComponent(); BindingContext = this; } } 在 CollectionView 中使用它时,直接使用模型的 Label 属性时绑定可以工作,但当数据通过我的 SectionTitle 组件传递时它不起作用。为 LabelText 设置静态值是有效的。 <?xml version="1.0" encoding="UTF-8" ?> <ContentPage x:Class="mater.Views.HygienePage" xmlns="http://schemas.microsoft.com/dotnet/2021/maui" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:c="clr-namespace:mater.Components" xmlns:local="clr-namespace:mater" xmlns:models="clr-namespace:mater.Models" xmlns:vm="clr-namespace:mater.ViewModels" x:DataType="vm:HygieneViewModel"> <ScrollView> <StackLayout Margin="0,10,0,0"> <CollectionView Margin="20,10,20,10" ItemsSource="{Binding Cards}" SelectionChanged="CollectionView_SelectionChanged" SelectionMode="Single"> <CollectionView.ItemsLayout> <GridItemsLayout HorizontalItemSpacing="20" Orientation="Vertical" Span="2" VerticalItemSpacing="20" /> </CollectionView.ItemsLayout> <CollectionView.ItemTemplate> <DataTemplate x:DataType="models:CardItem"> <StackLayout Margin="0,0,0,10" Background="{StaticResource LightGrey}"> <Grid ColumnDefinitions="Auto,*"> <Border Grid.Column="0" Margin="0,10,0,0" Padding="5,10,20,10" Background="{StaticResource Coral}" StrokeShape="RoundRectangle 0,10,0,10"> <Label Text="{Binding Label}" /> </Border> <Grid Grid.Column="1" /> </Grid> <!-- Here if I put LabelText="ASD" it works, with the binding it doesn't work, the binding 3 lines before works --> <c:SectionTitle BGColor="{StaticResource Coral}" LabelText="{Binding Label}" /> <Image HeightRequest="150" Source="{Binding Icon}" /> </StackLayout> </DataTemplate> </CollectionView.ItemTemplate> </CollectionView> </StackLayout> </ScrollView> </ContentPage> 为了完整性,我还添加了相应的 C# 代码 using mater.ViewModels; using mater.Models; using mater.Resources.Strings; namespace mater.Views; public partial class HygienePage : ContentPage { public List<CardItem> Cards = new() { new CardItem { Icon="rischi_micro.png", Label=AppStrings.SicRischi }, new CardItem { Icon="da_evitare.png", Label=AppStrings.SicEvitare }, new CardItem { Icon="acquisto.png", Label=AppStrings.SicLavaggio }, new CardItem { Icon="cottura.png", Label=AppStrings.SicCottura }, new CardItem { Icon="contaminazioni.png", Label=AppStrings.SicContaminazioni }, }; public HygieneViewModel vm { get; set; } public HygienePage() { InitializeComponent(); vm = new HygieneViewModel(); vm.Cards = Cards; BindingContext = vm; } async void CollectionView_SelectionChanged(object sender, SelectionChangedEventArgs e) { if (e.CurrentSelection.Count > 0) { CardItem selectedCard = (CardItem)e.CurrentSelection[0]; ((CollectionView)sender).SelectedItem = null; switch (selectedCard.Label) { case var value when value == AppStrings.SicRischi: await Shell.Current.GoToAsync("rischimicropage"); break; case var value when value == AppStrings.SicEvitare: await Shell.Current.GoToAsync("evitarepage"); break; case var value when value == AppStrings.SicLavaggio: await Shell.Current.GoToAsync("lavaggiopage"); break; case var value when value == AppStrings.SicCottura: await Shell.Current.GoToAsync("cotturapage"); break; case var value when value == AppStrings.SicContaminazioni: await Shell.Current.GoToAsync("contaminazionipage"); break; default: break; } } } } CardItem 模型: using System; namespace mater.Models; public class CardItem { public ImageSource Icon { get; set; } public string Label { get; set; } public bool isVisible { get; set; } = true; } 和视图模型: using System; using CommunityToolkit.Mvvm.ComponentModel; using mater.Models; namespace mater.ViewModels; public partial class HygieneViewModel: ObservableObject { [ObservableProperty] private List<CardItem> cards; } 知道我的绑定做错了什么吗? 正如 @Jason 在评论中强调的那样,问题是在控件中使用 BindingContext=this 。 我从 C# 的构造函数中删除了 BindingContext = this; 向控件添加了 x:Name,并且绑定源更新如下: <?xml version="1.0" encoding="utf-8" ?> <ContentView x:Class="mater.Components.SectionTitle" xmlns="http://schemas.microsoft.com/dotnet/2021/maui" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:c="clr-namespace:mater.Components" x:Name="self" x:DataType="c:SectionTitle"> <Grid ColumnDefinitions="3*,2*"> <Grid ColumnDefinitions="Auto,*"> <Border x:Name="Bordo" Grid.Column="0" Padding="5,10,20,10" Background="{Binding Source={x:Reference self}, Path=BGColor}" StrokeShape="RoundRectangle 0,10,0,10"> <Label x:Name="Lbl" Grid.Column="0" Text="{Binding Source={x:Reference self}, Path=LabelText}" /> </Border> </Grid> </Grid> </ContentView> 现在一切正常

回答 1 投票 0

在 Azure C# 中设置带有 webapp 绑定的自定义域

我正在寻找添加自定义域并绑定到 Azure 中的 web 应用程序的方法。 我开发了一些添加自定义域的东西,但没有绑定,所以它的状态仍然没有绑定(不安全......

回答 1 投票 0

DataGridComboBoxColumn 数据绑定

我正在尝试对 DataGridComboBoxColumn 进行数据绑定 ...

回答 5 投票 0

与 x 引用的 XAML 绑定不起作用,但与代码的相同绑定有效 - 为什么?

我有一个 ContentView,它公开了一个布尔属性,您可以将其绑定到: 公共静态只读 BindableProperty ShowCurrentIntervalInfoProperty = BindableProperty.Create(nameof(

回答 1 投票 0

在代码后面创建样式触发器,只有 2 个设置器之一正在工作

BorderThicknessProperty 已正确应用,但 ForeGroundProperty 未正确应用。我尝试过交换二传手的位置,认为可能只有第一个被应用。我有...

回答 1 投票 0

如何在XAML中绑定TextBlock的x:Uid?

我正在制作一个可以显示多种语言的菜单,所以我想在每个项目上设置这些TextBlock的Uid,如何通过数据绑定在XAML中设置TextBlock的Uid。因为当我设置 x:...

回答 2 投票 0

绑定到 WPF XAML 中的动态对象

我正在实习初级C#开发人员的职位,遇到了以下问题。在XAML布局中,项目中会生成相当多的动态块。他们不能通过

回答 1 投票 0

如何在DataTemplate中绑定两个不同的类属性

我正在尝试绑定 DataTemplate 中不同类的两个属性。 我正在尝试绑定 DataTemplate 中不同类的两个属性。 <DataTemplate x:Key="DemoItemTemplate" x:DataType="local:DemoInfo"> <NavigationViewItem Visibility="{Binding Visibility, Mode=TwoWay}" Content="{x:Bind Name}"/> </DataTemplate> 将此 DataType 的 DemoInfo 设置为 DataTemplate,并从 Name 更新 DemoInfo 值。 我尝试过将视图模型视为源和相对源绑定。但是 Visibility 属性绑定在 ViewModel 类中不起作用。有什么建议如何实现这一目标吗? Visibility="{Binding Visibility, Source={StaticResource viewModel}}" AFAIK,你不能在 UWP 中使用多重绑定,你可以尝试使用 Locator 什么是 ViewModelLocator,与 DataTemplates 相比,它的优点/缺点是什么? 如何在DataTemplate中绑定两个不同的类属性 如果您将 Visibility 与 StaticResource 绑定,请在页面 Resources 中声明 ViewModel 类,如下所示。 视图模型 public class ViewModel { public ViewModel() { Visibility = false; } public bool Visibility { get; set; } } Xaml <Page.Resources> <local:ViewModel x:Key="ViewModel" /> </Page.Resources> <DataTemplate x:DataType="local:Item"> <TextBlock Width="100" Height="44" Text="{x:Bind Name}" Visibility="{Binding Visibility, Source={StaticResource ViewModel}}" /> </StackPanel> </DataTemplate> 更新 如果您希望 Visibility 值在运行时动态更改,您需要为 ViewModel 类实现 INotifyPropertyChanged 接口。 public class ViewModel : INotifyPropertyChanged { public ViewModel() { Visibility = false; } private bool _visibility; public bool Visibility { get { return _visibility; } set { _visibility = value; OnPropertyChanged(); } } public event PropertyChangedEventHandler PropertyChanged; private void OnPropertyChanged([CallerMemberName] string PropertyName = null) { PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(PropertyName)); } } 更多详情请参考深度数据绑定官方文档 我可能是错的,但我认为 Visibility 属性有一个专用枚举,其中包含 Visibility 属性的所有可能选项(Visibility Enum)。因此,您的绑定可能工作得很好,但绑定属性的 Type 需要使用 Visibility 为 System.Windows 类型。 顺便说一句,我无论如何都不会在视图模型中添加可见性属性。我认为更标准的方法是在绑定视图后面的直接代码中具有可见性DependencyProperty。

回答 3 投票 0

Value 和@bind-Value 之间的区别?

我正在查看InputCheckBox的文档https://learn.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.components.forms.inputcheckbox,我发现它公开了要绑定的值到 desi...

回答 2 投票 0

当我将相同的属性绑定到另一个ListView时,ListView保持为空

如果我将相同的属性绑定到相同类型的另一个控件,在我的例子中绑定到 ListView,那么第一个 ListView 将填充对象,但第二个 ListView 保持为空。我和 On 一起玩...

回答 1 投票 0

JAXB 避免从 XSD 生成重复类

我有一个 xsd,其中有一个名为 toc 的元素在 xsd 中两次。它会导致 java 类生成错误。现在,我想编写 xml 绑定来解决这个问题。 我有一个 xsd,其中有一个名为 toc 的元素在 xsd 中两次。它会导致 java 类生成错误。现在,我想编写 xml 绑定来解决这个问题。 <jaxb:bindings schemaLocation="../DMS_Dokument.Versenden_response.xsd"> <jaxb:bindings node="xsd:element[@name='toc']"> <jaxb:factoryMethod name="TOC"/> </jaxb:bindings> </jaxb:bindings> 我得到的错误是 原因:无法解析schema。应该提供错误消息 为了避免 JAXB 从 XSD 生成重复的类,您可以使用本地或外部绑定为生成的类定义不同的名称。 <jaxb:bindings node="XPATH"> <jaxb:class name="YourDistinctName"/> </jaxb:bindings> Java 类名重复的一个原因是在全局绑定中使用 toplevel 作用域。 注意: localScoping 属性的值可以是 nested 或 toplevel。此属性描述嵌套 XML 模式组件与嵌套模式派生的 JAXB 类或顶级模式派生的 JAXB 类的 JAXB 绑定。为了避免嵌套组件之间的命名冲突,该属性的默认值是嵌套的。当模式组件嵌套太深或应用程序不希望使用嵌套类或使用 JPA 时(JPA 第 2.1 节,实体必须是顶级类),开发人员可以将 localScoping 自定义为 toplevel。 例如,下载此演示 (zip) 并考虑其 XML 架构 trilogy.xsd,该架构对 Trilogy 书籍进行建模。它在根 trilogy 元素上定义一个 TOC,并为每个 book 定义另一个 TOC。该架构将每个 TOC 定义为匿名类型,并且每个 TOC 都有不同的用途。第一个目录描述了三本书的标题,但第二个目录是每本书的章节列表。两者具有相同的元素名称 <toc>...</toc>,如该 XML 实例 trilogy.xml 所示,但需要不同的 Java 类定义。 当模式被定制为使用 <jaxb:globalBindings localScoping=”toplevel”/> 时,JAXB 会尝试根据一个元素名称生成两种类型,这会导致名称冲突。 为了解决 Java 类名重复问题,演示使用 HiSrc BasicJAXB 项目中的工具来扫描 XSD 并输出这些建议的绑定:trilogy.xjb。例如,这是书 TOC 的装订: <jaxb:bindings node="//xs:element[@name='trilogy']/xs:complexType/xs:sequence/xs:element[@name='book']/xs:complexType/xs:sequence/xs:element[@name='toc']/xs:complexType"> <jaxb:class name="TrilogyBookTocType"/> </jaxb:bindings> 绑定使用 XPATH 选择目标节点,并将 Java 类名称声明为 TrilogyBookTocType。 演示提供了一个 bash 脚本来运行该工具,但它可以像这样手动运行... java -cp \ $HOME/.m2/repository/org/patrodyne/jvnet/hisrc-basicjaxb-tools/2.1.1/hisrc-basicjaxb-tools-2.1.1.jar \ org.jvnet.basicjaxb.util.CreateToplevelXJBindings \ --nested src/main/resources/trilogy.xsd 该工具将其输出发送到 stdout,您可以在其中将其复制/粘贴到绑定文件或架构中。 执行 该演示是一个独立的 Maven 项目。您可以使用以下命令运行测试: mvn -Ptest clean test mvn -Pexec compile exec:java 方法 hisrc-higherjaxb-maven-plugin 配置为使用提供的 trilogy.xsd 模式和绑定文件 trilogy.xjb 生成 JAXB 类。该模式提供了命名空间 "http://org.example/trilogy",JAXB 使用它来使用自己的命名约定创建 Java package 名称。 作为一个选项,可以使用这些 XJC hisrc-basicjaxb-plugins 生成 Java 内置 Object 方法的更高级实现。特别是,示例项目使用 toString 插件来显示未编组的 Trilogy 对象的人类可读表示。 hisrc-basicjaxb-插件 <args> <arg>-no-header</arg> <arg>-XhashCode</arg> <arg>-Xequals</arg> <arg>-XtoString</arg> </args> 注意: 使用 XJC hisrc-basicjaxb-plugins 时,运行时类路径需要 hisrc-basicjaxb-runtime 依赖。 测试 JUnit 测试类 TrilogyTest.java 扫描示例文件并调用方法 checkSample(File sample) 将每个文件提供给测试人员。对于此项目,创建了一个 JAXBContext,并且 samples 路径中的每个文件都被 unmarshaled 为 Trilogy 对象。成功后,每个对象都会被编组以用于日志记录和您的审查。 示范 具有 main(...) 方法的 Java 标准引擎应用程序位于 org.example.trilogy.Main。该应用程序使用以下命令执行: mvn -Pexec compile exec:java -Dexec.args="src/test/samples/trilogy.xml" 免责声明:我是这些HiSrc项目的维护者。

回答 1 投票 0

© www.soinside.com 2019 - 2024. All rights reserved.