binding

How can you bind an Indexed property to a control in WPF

对着背影说爱祢 提交于 2019-12-28 13:04:14
问题 Given an instance of the class ThisClassShouldBeTheDataContext as the Datacontext for the view class ThisClassShouldBeTheDataContext { public Contacts Contacts {get;set;} } class Contacts { public IEnumerable<Person> Persons {get;set;} public Person this[string Name] { get { var p = from i in Persons where i.Name = Name select i; return p.First(); } } } class Person { public string Name {get;set;} public string PhoneNumber {get;set;} } How can I bind Contact["John"].PhoneNumber to a textbox?

How can you bind an Indexed property to a control in WPF

佐手、 提交于 2019-12-28 13:03:06
问题 Given an instance of the class ThisClassShouldBeTheDataContext as the Datacontext for the view class ThisClassShouldBeTheDataContext { public Contacts Contacts {get;set;} } class Contacts { public IEnumerable<Person> Persons {get;set;} public Person this[string Name] { get { var p = from i in Persons where i.Name = Name select i; return p.First(); } } } class Person { public string Name {get;set;} public string PhoneNumber {get;set;} } How can I bind Contact["John"].PhoneNumber to a textbox?

When to use a WPF Dependency Property versus INotifyPropertyChanged

倖福魔咒の 提交于 2019-12-28 11:44:11
问题 Do folks have any guidance on when a simple .NET property that fires INotifyPropertyChanged.PropertyChanged is sufficient in a view model? Then when do you want to move up to a full blown dependency property? Or are the DPs intended primarily for views? 回答1: There are a few approaches: 1. The dependency property While you using the dependency property it makes the most sense in elements-classes that have a visual appearance ( UIElement s). Pros: WPF do the logic stuff for you Some mechanism

WPF TwoWay Binding to a static class Property

耗尽温柔 提交于 2019-12-28 06:25:14
问题 There's no problem if Mode=OneWay, but I have this: Class: namespace Halt { public class ProjectData { public static string Username {get;set;} } } And XAML: xmlns:engine="clr-namespace:Halt.Engine" <TextBox Name="UsernameTextBox" HorizontalAlignment="Stretch" Margin="10,5,10,0" Height="25" Text="{Binding Source={x:Static engine:ProjectData.Username}, Mode=TwoWay}"/> This dont wanna work because of TwoWay mode. So how to fix it? 回答1: If the binding needs to be two-way, you must supply a path.

A 'Binding' can only be set on a DependencyProperty of a DependencyObject

做~自己de王妃 提交于 2019-12-28 05:36:18
问题 From a custom control based on TextBox , I created a property named Items , in this way: public class NewTextBox : TextBox { public ItemCollection Items { get; set; } } When using the custom control in XAML, I cannot bind the property because it raises exception "A 'Binding' can only be set on a DependencyProperty of a DependencyObject.". How do I solve this exception? 回答1: As a side note, it is also worth noting that you will get these binding errors if you copy and paste between objects and

A 'Binding' can only be set on a DependencyProperty of a DependencyObject

跟風遠走 提交于 2019-12-28 05:36:16
问题 From a custom control based on TextBox , I created a property named Items , in this way: public class NewTextBox : TextBox { public ItemCollection Items { get; set; } } When using the custom control in XAML, I cannot bind the property because it raises exception "A 'Binding' can only be set on a DependencyProperty of a DependencyObject.". How do I solve this exception? 回答1: As a side note, it is also worth noting that you will get these binding errors if you copy and paste between objects and

Assembly binding redirect does not work

余生颓废 提交于 2019-12-28 04:00:48
问题 I'm trying to set up an assembly binding redirect, using the following app.config: <configuration> <runtime> <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> <dependentAssembly> <assemblyIdentity name="Microsoft.AnalysisServices" PublicKeyToken="89845dcd8080cc91" /> <bindingRedirect oldVersion="10.0.0.0" newVersion="9.0.0.0" /> </dependentAssembly> </assemblyBinding> </runtime> </configuration> I'm running the program on a machine with version 9.0.242.0 in the GAC, with the

Binding WPF DataGrid to DataTable using TemplateColumns

半腔热情 提交于 2019-12-28 01:11:50
问题 I have tried everything and got nowhere so I'm hoping someone can give me the aha moment. I simply cannot get the binding to pull the data in the datagrid successfully. I have a DataTable that contains multiple columns with of MyDataType public class MyData { string nameData {get;set;} bool showData {get;set;} } MyDataType has 2 properties (A string, a boolean) I have created a test DataTable DataTable GetDummyData() { DataTable dt = new DataTable("Foo"); dt.Columns.Add(new DataColumn(

In bash, how do I bind a function key to a command?

只谈情不闲聊 提交于 2019-12-27 11:35:39
问题 Example: I want to bind the F12 key to the command echo "foobar" such that every time I hit F12 the message "foobar" will be printed to screen. Ideally it could be any arbitrary shell command, not just builtins. How does one go about this? 回答1: You can determine the character sequence emitted by a key by pressing Ctrl - v at the command line, then pressing the key you're interested in. On my system for F12 , I get ^[[24~ . The ^[ represents Esc . Different types of terminals or terminal

Early and late binding

匆匆过客 提交于 2019-12-27 11:09:27
问题 I'm trying to get my head around when early/late binding occurs in C#. Non-virtual methods are always early bound. Virtual methods are always late bound: the compiler inserts extra code to resolve the actual method to bind to at execution time and checks for type safety. So subtype polymorphism uses late binding. Calling methods using reflection is an example of late binding. We write the code to achieve this as opposed to the compiler. (E.g. calling COM components.) VB.NET supports implicit