Tag: 绑定

绑定的延迟属性来自.Net 4.0中的.Net 4.5

如何在.Net 4.0中实现关于绑定的.Net 4.5( 此处描述)的延迟属性? 我知道我不能inheritanceBindingBase,因为ProvideValue是密封的。 我可以实现MarkupExtension,但这意味着我现在必须重写BindingExtension中的所有属性还有其他方法吗?

使用MVVM双向绑定到AvalonEdit文档文本

我想在我的MVVM应用程序中包含一个AvalonEdit TextEditor控件。 我需要的第一件事是能够绑定到TextEditor.Text属性,以便我可以显示文本。 为此,我遵循了Make AvalonEdit MVVM兼容的示例。 现在,我已使用接受的答案作为模板实现了以下类 public sealed class MvvmTextEditor : TextEditor, INotifyPropertyChanged { public static readonly DependencyProperty TextProperty = DependencyProperty.Register(“Text”, typeof(string), typeof(MvvmTextEditor), new PropertyMetadata((obj, args) => { MvvmTextEditor target = (MvvmTextEditor)obj; target.Text = (string)args.NewValue; }) ); public new string Text { get { return base.Text; } set { base.Text = value; } } […]

将静态数据绑定为字典键

如何将字典静态数据绑定为字典键? 我的XAML代码: 字典键的静态数据类: public static class DataNames { public static string SomeDataName { get; } = “some_data_name”; … } 如何将DataNames.SomeDataName绑定为XAML代码中我的字典的键? UPDATE 我使用字典转换器,然后将其绑定为StaticResource xmlns:converters=”clr-namespace:AppName.Converters” … … Text=”{Binding Path=DataStructure, Converter={StaticResource SomeConverter}, ConverterParameter={x:Static data:DataNames.SomeDataName}}” 感谢mm8帮助解决方案。 他的回答包含字典转换器的代码。

命名空间前缀“utilities”未定义

我是WPF的新手…我试图将validation绑定到WPF中的文本框。 这是我在xaml中的文本框: 这是我的validation课: public class PingValidationRule : ValidationRule { public override ValidationResult Validate(object value, System.Globalization.CultureInfo cultureInfo) { … if (ipCorrect) return new ValidationResult(true, null); else return new ValidationResult(false, “It’s not an IP”); } } 有这个我有以下错误: 错误未定义名称空间前缀“utilities”。 谁知道为什么?

使用mvvm在xamarin表单中的视图之间传递数据

我正在尝试在页面之间导航并同时绑定数据。 这是我尝试过的: public ICommand GetIdeasCommand { get { return new Command(async () => { Ideas = await _apiServices.GetIdeasAsync(); await Application.Current.MainPage.Navigation.PushAsync(new IdeasSinglePage(Ideas)); }); } } 假设Ideas是我从json获得的数组列表。 但是这个方法对我没有帮助,因为我得到一个空白页面。 此外,如果我在页面内调用此function一切都很好。 这篇文章给了我一个想法: 如何在Xamarin.Forms中将参数从一个页面传递到另一个页面? 我的看法 : 代码背后: public partial class IdeasSinglePage : ContentPage { public IdeasSinglePage(List ideas) { InitializeComponent(); this.BindingContext = new IdeasSinglePage(ideas); //the app breaks here } } 谢谢。

当DataGrid发生更改时,为什么我的ViewModel中的属性没有更新?

我正在尝试创建一个UserControl,它允许我在网格中编辑Dictionary类型的Dictionary (只编辑条目到目前为止,不添加或删除)。 每当我将DataGrid绑定到Dictionary时,它将网格显示为只读,因此我决定创建一个值转换器,将其转换为ObservableCollection ,其中DictionaryEntry只是一个具有两个属性Key和Value 。 这适用于在网格中显示字典,但现在当我对网格进行更改时,我的字典没有被更新。 我不确定为什么。 我认为这是我设置绑定的方式或我的值转换器的问题。 如果有人能够发光,那就太棒了。 下面是我能做的最小的演示,它展示了我正在做的事情。 问题是当我更改网格中的值时,我的MainViewModel上的MyDictionary不会更新。 为什么? MainViewModel.cs public class MainViewModel : INotifyPropertyChanged { public MainViewModel() { _myDictionary = new Dictionary() { {“Key1”, “Value1”}, {“Key2”, “Value2”}, {“Key3”, “Value3”} }; } private Dictionary _myDictionary; public Dictionary MyDictionary { get { return _myDictionary; } set { if (_myDictionary == value) return; _myDictionary […]

ControlTemplate中的DataTemplate不更新Binding

我创建了一个带有3个PART_s的控件,一个PART_根据绑定的类型而改变,但是在Control中更改的值不会更新Binding,它似乎可以作为OneWay绑定使用。 以下是我相信的代码的一部分: …. BooleanDAView DateTimeDAView Int32DAView StringDAView 对于内容我也尝试过… RelativeSource={RelativeSource AncestorType=local:DABaseControl}但没有变化。 如果DataTemplate Binding使用”{Binding Path=Content, RelativeSource={RelativeSource TemplatedParent}, Mode=TwoWay}”则模板在设置后不会更改。 或者有更好的方法吗? 谢谢

WPF将当前项目从列表传递到usercontrol

我绑定到ObservableCollection Stages作为ItemsControl的ItemsSource: 有没有办法将当前阶段对象传递给item datatemplate中的usercontrol,如下所示: 真正的问题是我需要将当前的Stage对象作为MyUserControl中的变量来对其进行一些操作。 将它传递给构造函数[如:MyUserControl(Stage s)]似乎是一种很好的方法,但是afaik没有办法在XAML中指定它。 有任何想法吗?

以编程方式检查DataBound CheckListBox

我有一个DataBound“CheckedListBox”,我需要检查一些项目。 我尝试使用以下代码… if (!string.IsNullOrEmpty(search.Languages)) { string[] langs = search.Languages.Split(‘,’); for (int i = 0; i < (langs.Length – 1); i++) { for (int j = 0; j < clbLang.Items.Count; j++) { string lng = clbLang.Items[j] as string; if (lng.Trim() == langs[i]) { clbLang.SetItemChecked(j, true); break; } } } } 没有错误,debuged执行正在经历“ 检查 ”过程,但最后我看不到任何检查它。 然后我添加了一个按钮并添加了以下代码。 ( 点击查看所有项目 […]

如何以编程方式绑定DataTemplate内部控件的(依赖)属性?

TextBlock驻留在DataTemplate ,因此我无法通过其名称来引用它。 那么如何以编程方式绑定其(例如) Text属性? XAML: … … 码: public partial class MyCustomControl : UserControl { … public static readonly DependencyProperty DataSourceProperty = DependencyProperty.Register(“DataSource”, typeof (IEnumerable), typeof (MyCustomControl), new PropertyMetadata(default(IEnumerable))); public IEnumerable DataSource { get { return (IEnumerable) GetValue(DataSourceProperty); } set { SetValue(DataSourceProperty, value); } } public static readonly DependencyProperty MemberPathProperty = DependencyProperty.Register(“MemberPath”, typeof (string), typeof […]