data-binding 相关问题

将两个数据/信息源绑定在一起并使它们保持同步的一般技术。

根据用户选择在WPF中显示数字的小数位

我想在WPF窗口中显示一些double类型的数字。应允许用户选择应显示多少位小数。 我想直接在视图(XAML)中解决这个问题,而不需要

回答 1 投票 0

使用WinUI3和XAML数据绑定,当源包含索引操作并且是子字段时,如何获取要更新的字段?

我有一个名为 PlayerState 的状态类,其中包含许多我想通过 XAML 绑定的字段,因此我需要一个可扩展的解决方案。 我在继承自 BindableBase 的 ViewModel 中有这段代码...

回答 1 投票 0

无法将数据绑定到 WinForms 应用程序的 WPF 控件中的 ComboBox;设计师做工不错

我有一个位于 ElementHost 中的 WPF 用户控件,因此可以在 WinForms 应用程序中使用它。在这个 WPF 用户控件上有一个 ComboBox,我正在尝试将老鼠的 ObservableCollection 数据绑定到它......

回答 1 投票 0

如何强制View更新Xamarin Forms中的绑定属性?

我想在内容页面中强制更新数据绑定属性。在本例中是 ContentPage Title 参数。 我想在内容页面中强制更新数据绑定属性。在本例中是 ContentPage Title 参数。 <ContentPage x:Class="Containers.Views.ContainerPage" xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" Title="{Binding SomeStringProperty}" Appearing="ContentPage_Appearing"> 我得到的最接近的是这个,但它不起作用。 private void ContentPage_Appearing(object sender, EventArgs e) { this.BindingContext = null; this.BindingContext = myClassInstance; } 我不想实施 onPropertyChange 事件。我只是想“刷新”视图的有界数据。 如果您的视图模型已经实现了 INotifyPropertyChanged - 您可以尝试使用 null/空参数引发 PropertyChangedEvent - 这应该强制更新所有绑定属性 - 更多详细信息请参见此处。 public void RaiseAllProperties() { PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(null)); } 对我有用的 CustomView 方法是: using Xamarin.Forms; namespace Xam.CustomViews.ContentsViews { [XamlCompilation(XamlCompilationOptions.Compile)] public partial class FeatherButton : ContentView { // ... Existing code ... public FeatherButton() { InitializeComponent(); PropertyChanged += OnPropertyChanged; } private void OnPropertyChanged(object sender, PropertyChangedEventArgs e) { if (e.PropertyName == StyleProperty.PropertyName) { UpdateVisualProperties(); } } private void UpdateVisualProperties() { OnPropertyChanged(nameof(TextColor)); OnPropertyChanged(nameof(BackgroundColor)); OnPropertyChanged(nameof(BorderColor)); OnPropertyChanged(nameof(BorderWidth)); } // ... Existing code ... } }

回答 2 投票 0

从 ViewModel 绑定标签文本不起作用

我目前正在学习 .NET MAUI,并且遇到了数据绑定问题。我已经阅读了 Microsoft 文档上有关数据绑定的部分,但我仍然不知道为什么它不...

回答 2 投票 0

qwik 中的双向道具

是否可以为qwik中的组件创建双向属性? 我想创建一个自定义输入组件,用于显示金额和单位的大小。 为了避免不必要的事件,我只是想...

回答 2 投票 0

WPF 重置按钮单击焦点

我有一个文本框和一个带有按钮的工具栏。如果我在文本框中键入内容并单击按钮,我希望文本框失去焦点,以便更新绑定。我不想添加 UpdateSourceTr...

回答 4 投票 0

PHP 绑定数组用于 SQL 插入

尝试绑定数组(第一个数组绑定)以防止 SQL 注入 这是工作代码: if (isset($_POST['checkbox_selected'])) { $valuesArr = 数组(); foreach ($_POST['

回答 2 投票 0

Delphi中使用Visual Binding结合涉及组件的FDQuery和OnClick事件时是否有Bug?

当您通过 LiveBinding 将 FDQuery 连接到编辑器和切换器时,当您更改查询中的其他连接数据时,切换器 IsCheched 状态会发生更改。 为了更好地理解这里有一个 Exa...

回答 0 投票 0

DataTemplate 中的用户控件依赖属性绑定 (TabControl.ContentTemplate)

我使用 DependencyProperty 创建了我的 UserControl。 当我在 TabControl.ContentTemplate 的 DataTemplate 中使用它时,数据绑定仍然粘在第一个选项卡对象上。 文本框数据箱...

回答 0 投票 0

从 ComboBox 中选择的值未传递给 WPF MVVM 应用程序中的方法

我正在使用 WPF 和 MVVM 模式构建一个复利计算器。我的视图中有一个组合框,允许用户选择复合间隔(例如“每日”、“每周”、“每月”等...

回答 0 投票 0

在 recyclerView 中的 editText 之间进行验证时遇到问题

我的要求是:- 默认情况下,时间(edittext)的 3 个空单元格将可见 如果我愿意,我可以通过单击回收器视图之外的按钮添加更多内容 在第 0 个位置我可以添加任何 t...

回答 0 投票 0

Content 和 DataContext 可以通过 Binding 同时工作吗?

我正在使用 (MainViewModel.cs) 中的类属性在运行时在 MainView.xaml 页面中加载视图和 ViewModel。 如果我仅绑定内容,则视图会加载,但我正在绑定......

回答 1 投票 0

WPF - Content 和 DataContext 可以同时通过 Binding 工作吗?

我正在使用 (MainViewModel.cs) 中的类属性在运行时在 MainView.xaml 页面中加载视图和 ViewModel。 如果我仅绑定内容,则视图会加载,但我正在绑定......

回答 1 投票 0

绑定到窗口的依赖属性

我想创建一个复选框来切换窗口的 Topmost 属性。 如果 TopMost 是 ViewModel 的属性,我会使用这个: T...

回答 1 投票 0

这是什么:找不到参数的 dataBinding() 方法?

在 BuildType$AgpDecolated_Decolated{name=buildFeatures、debuggable=false、testCoverageEnabled=false、jniDebuggable=false、pseudoLocalesEnabled=

回答 1 投票 0

如何在 WinUI 3 中以 TwoWay 数据绑定嵌套 INotifyPropertyChanged ViewModel 到 ListView 内的 ComboBox?

我正在尝试对我的其他问题实施建议的解决方案。目标是使用数据绑定代替处理 ComboBox Loaded 事件。 我有两个嵌套的 ViewModel 我正在尝试

回答 1 投票 0

Dotnet Maui:无法绑定 BindableProperty。解决办法是什么?

这里是主页,经典。 主页.xaml 这里是主页,经典。 主页.xaml <?xml version="1.0" encoding="utf-8" ?> <ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:view="clr-namespace:SuperLabelApp.Resources.Views" x:Class="SuperLabelApp.MainPage"> <view:SuperLabel Text="Hello, World"/> </ContentPage> MainPage.xaml.cs namespace SuperLabelApp; public partial class MainPage : ContentPage { public MainPage() { InitializeComponent(); } } SuperLabel 有一个可绑定的 Text 属性,我希望他将其传递给 SuperLabelChild,以便其标签使用主页中的值进行更新。 超级标签.xaml <?xml version="1.0" encoding="utf-8" ?> <ContentView xmlns="http://schemas.microsoft.com/dotnet/2021/maui" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:view="clr-namespace:SuperLabelApp.Resources.Views" x:Class="SuperLabelApp.Resources.Views.SuperLabel"> <view:SuperLabelChild Text="{Binding Text}" /> </ContentView> SuperLabel.xaml.cs namespace SuperLabelApp.Resources.Views; public partial class SuperLabel : ContentView { #region [Constructor] public SuperLabel() { this.InitializeComponent(); this.BindingContext = this; } #endregion #region [Bindable Properties] public static readonly BindableProperty TextProperty = BindableProperty.Create( nameof(Text), typeof(string), typeof(SuperLabel), default(string), propertyChanged: onchanged ); #endregion #region [Properties] public string Text { get => (string)this.GetValue(TextProperty); set => this.SetValue(TextProperty, value); } #endregion static void onchanged(BindableObject obj, object oldValue, object newValue) { Console.WriteLine("Debug Super Label"); } } SuperLabelChild.xaml <?xml version="1.0" encoding="utf-8" ?> <ContentView xmlns="http://schemas.microsoft.com/dotnet/2021/maui" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="SuperLabelApp.Resources.Views.SuperLabelChild"> <Label Text="{Binding Text}" /> </ContentView> SuperLabelChild.xaml.cs namespace SuperLabelApp.Resources.Views; public partial class SuperLabelChild : ContentView { #region [Constructor] public SuperLabelChild() { this.InitializeComponent(); this.BindingContext = this; } #endregion #region [Bindable Properties] public static readonly BindableProperty TextProperty = BindableProperty.Create( nameof(Text), typeof(string), typeof(SuperLabelChild), default(string), propertyChanged: onchanged ); #endregion #region [Properties] public string Text { get => (string)this.GetValue(TextProperty); set => this.SetValue(TextProperty, value); } #endregion static void onchanged(BindableObject obj, object oldValue, object newValue) { Console.WriteLine("Debug Super Label Child"); } } MainPage 中的值永远不会到达 SuperLabelChild。当我更改“Hello, World”时,会触发 SuperLabel 的 onchanged 事件,但不会触发 SuperLabelChild 中的事件。 如果我将 SuperLabel.xaml 的绑定更改为“Hi”等文本,我会到达 onchanged 事件,并且 UI 中的标签将更改为“Hi”。 我知道我可能做错了什么,但为什么它可以与以下绑定一起使用: SuperLabel->SuperLabelChild->Label, 但不是为了 MainPage->SuperLabel->SuperLabelChild 我错过了什么吗? 请注意,这个示例很简单,只是我遇到的实际问题的复制。 我尝试更改绑定、更改顺序。 以两种方式制作 BindableProperty。 我期望 SuperLabel 的绑定能够通知其对 SuperLabelChild 的更改,但事实并非如此。 我知道我可以使用 c# 来更改标签的值,但我想了解绑定是如何工作的,并且很难调试。 您可以使用 控件模板,然后使用 TemplateBinding 传递参数,这会将 ControlTemplate 中元素的属性绑定到由模板化自定义控件或模板化页面定义的公共属性。 因此更改您的SuperLabelChild.xaml,如下所示: <ContentView.ControlTemplate> <ControlTemplate> <VerticalStackLayout> <Label Text="{TemplateBinding Text}" /> <ContentPresenter/> </VerticalStackLayout> </ControlTemplate> </ContentView.ControlTemplate> 更多详情可以参考使用TemplateBinding传递参数。 做一些改变,它就会起作用。 对于SuperLabel.xaml, <ContentView xmlns="http://schemas.microsoft.com/dotnet/2021/maui" ... x:Name="superLabel"> <view:SuperLabelChild Text="{Binding Text,Source={x:Reference superLabel}}" /> </ContentView> 对于 SuperLabelChild.xaml, <ContentView xmlns="http://schemas.microsoft.com/dotnet/2021/maui" ... x:Name="superLabelChild"> <Label Text="{Binding Text,Source={x:Reference superLabelChild}}" /> </ContentView> 此外,您不必在这两个文件中设置this.BindingContext=this。 更多信息,您可以参考.NET MAUI ContentView。

回答 2 投票 0

C# WinForms 主从数据绑定中的多个子网格

这就是我正在尝试做的事情: VS 2022,.NET Framework 4.8 Windows 窗体应用程序 所有数据处理都是DataSets、DataTables等,全部由设计器生成。 在表单上,我有一个 DataGridView (...

回答 1 投票 0

如何绑定到字典中的集合值

上下文: 在带有社区工具包 MVVM 的 .Net Maui 中 我有一个工作绑定: [ObservableProperty] ObservableCollection 项目; CollectionView 更新其项目的位置......

回答 1 投票 0

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