Tag: 绑定

INotifyPropertyChanged和线程

我有一个实现INotifyPropertyChanged的基类: protected void OnNotifyChanged(string pName) { if (PropertyChanged != null) { PropertyChanged(this, new PropertyChangedEventArgs(pName)); } } public event PropertyChangedEventHandler PropertyChanged; 我有一个带有Latitude属性的派生类,如下所示: private double latitude; public double Latitude { get { return latitude; } set { latitude = value; OnNotifyChanged(“Latitude”); } } 我的派生类也有一个方法Fly来操纵Latitude 。 我还有一个Form,其TextBox绑定到我的派生类的Latitude : txtLat.DataBindings.Clear(); txtLat.DataBindings.Add(“Text”, bindSrc, “Latitude”); 一个线程用于启动Fly如下所示: Thread tFly = new Thread(f.Fly); […]

在wpf mvvm中绑定时间跨度,并且仅显示分钟:秒?

我希望能够在文本框中设置分钟和秒。 我现在只是将我的文本框绑定到属性,这是一个TimeSpan属性。 所以现在在我的文本框中,默认为:00:00:00。 这很好,但我希望能够有00:00。 这样就可以消除时间。 我该怎么做呢? 我在网上搜索但找不到任何好的解决方案 谢谢! 这是我的约束力: public TimeSpan MaxTime { get { if (this.Examination.MaxTime == 0) return TimeSpan.Zero; else return maxTime; } set { maxTime = value; OnPropertyChanged(“MaxTime”); TimeSpan x; this.Examination.MaxTime = int.Parse(maxTime.TotalSeconds.ToString()); } }

以编程方式绑定ItemsSource

c#代码中的等价物是什么? … 我已经尝试了以下代码,但它似乎不起作用…… Binding b = new Binding(); b.Path = new PropertyPath(“taskItems”); DependencyProperty dp = DependencyProperty.Register(“itemsSource”, typeof(object), typeof(object), null); BindingOperations.SetBinding(taskItemListView, dp, b); 编辑 : 基于@ sa_ddam213的答案,这有效: Binding dataContextBinding = new Binding(); dataContextBinding.Path = new PropertyPath(“SelectedItem”); dataContextBinding.Source = itemListView; BindingOperations.SetBinding(taskItemListView, ListView.DataContextProperty, dataContextBinding ); Binding sourceBinding = new Binding(); sourceBinding.Path = new PropertyPath(“taskItems”); BindingOperations.SetBinding(taskItemListView, ListView.ItemsSourceProperty, sourceBinding );

在xamarin表单上动态绑定图像源

我的问题是,我可以将字符串图像绑定到图像源吗? 我有多个图像,如果条件,图像将会改变。 所以: Xamal上的Xamlforms: Codebehind c# public String someImage; public String SomeImage { set { if (someImage != value) { someImage = value; } } get { return someImage; } } InitializeComponent部分: if(true) { someImage = “backgroundListViewGren.png”; } else { someImage = “backgroundListViewRed.png”; } 图像位于便携式项目的“Images”文件夹中 但是,这不起作用,也许我不会做什么,但我不明白。 有解决方案? 我尝试使用ImageSource而不是字符串,但也不用。

C#/ WPF:获取DataTemplate中元素的绑定路径

如何在DataTemplate中获取元素的绑定路径? 我的XAML看起来像这样: 获取“普通”GridViewColumnHeader.DisplayMemberBinding的绑定路径是 var field = (string)((Binding)((GridViewColumnHeader)e.OriginalSource).Column.DisplayMemberBinding).Path.Path; 如何在TextBlock.Text的绑定路径中获得相同的内容?

为什么WPF ComboBox项目没有更新?

我不明白为什么在我的下面的例子中,“Billing Model”combobox在文本框中没有显示属性BillingModel.BillingModelDescription。 选择客户端后,我希望combobox显示当前的billng模型描述,但它保持空白。 绑定到同一事物的文本框确实显示了描述。 我有一些可能的模型作为ItemsSource,它工作正常。 如何在选择客户端时更新计费模型combobox? 这是XAML: 和代码隐藏(这只是一个例子,我在完整的应用程序中使用MVVM等,但这有助于说明问题): public partial class MainWindow : Window, INotifyPropertyChanged { public MainWindow() { AllClientData = new ObservableCollection(); AllBillingModels = new ObservableCollection(); ClientRate uno = new ClientRate(); uno.BillingModel = new BillingModelType(); uno.BillingModel.BillingModelID = 3; uno.BillingModel.BillingModelDescription = “Free”; uno.ID = 01; uno.EmployerName = “Employer1”; ClientRate dos = new ClientRate(); dos.BillingModel = […]

将combobox与wpf中的另一个combobox结合

我在wpf中有两个combobox,其中一个combobox看起来像这样: 我想知道如何绑定第二个combobox2以列出特定的car对makeobox1中的选定项目。 如果Peurgeut被选中,那么在combobox2中应该有一个列表: 106 206 306 或者如果选择了宝马 4 series 5 series 等等

获取组中的选定单选按钮(WPF)

我的程序中有一个ItemsControl ,其中包含单选按钮列表。 如何以MVVM方式在“ Insertions ” 组中找到所选单选按钮? 我在互联网上找到的大多数例子都涉及在转换器的帮助下设置绑定IsChecked属性的各个布尔属性。 是否有我可以绑定的ListBox SelectedItem的等价物?

绑定到UserControl DependencyProperty

我创建了一个带有一些DependencyProperties的UserControl(在这个例子中只有一个字符串属性)。 当我实例化Usercontrol时,我可以设置UserControl的属性,并按预期显示。 当我尝试通过Binding替换静态文本时,不显示任何内容。 我的UserControl如下所示: 守则背后是: namespace TestUserControBinding { public partial class MyUserControl : UserControl { public MyUserControl() { InitializeComponent(); this.DataContext = this; } public static readonly DependencyProperty MyTextProperty = DependencyProperty.Register( “MyText”, typeof(string), typeof(MyUserControl)); public string MyText { get { return (string)GetValue(MyTextProperty); } set { SetValue(MyTextProperty, value); } }// MyText } } 当我在MainWindow中尝试这个时,一切都如预期: 但这不起作用: 标签的行为是正确的,因此属性“文本”没有问题 我的错是什么? […]

多级标题GridView WPF

我需要将listview视图设置为gridview,它具有像这样的复杂标题(基于我创建的3维对象列表): | ———- LEVEL 0 ———— | | — Level 1a — | — Level 1b — | | Lvl A | Lvl B | Lvl A | Lvl B | 编辑:这是我的对象模型更少 public class Measures { public string Caption { get; set; } public List ThresholdList { get; set; } } public class Threshold { […]