Click here to Skip to main content
       

Silverlight / WPF

 
AnswerRe: DispatcherTimer Tick event not fired PinmemberPaulo Zemek23-Jan-13 6:28 
QuestionWhich way to load entity child collections? PinmemberUCLAdam16-Jan-13 5:11 
QuestionWPF with Web PinmemberRishabh Kumar14-Jan-13 8:42 
AnswerRe: WPF with Web PinmemberAbhishek Pant14-Jan-13 9:17 
AnswerRe: WPF with Web PinmvpAbhinav S16-Jan-13 17:20 
QuestionWPF - Bind IsEnabled To Method On VM PinmemberKevin Marois13-Jan-13 11:06 
AnswerRe: WPF - Bind IsEnabled To Method On VM PinmentorWayne Gaylard14-Jan-13 0:55 
AnswerRe: WPF - Bind IsEnabled To Method On VM PinmemberRichard Deeming14-Jan-13 2:13 
If you're using .NET 4.0 or 4.5, you can combine a single property with a dynamic object to achieve this:
public interface ICanEnableField
{
   bool CanEnableField(string key);
}
 
public sealed class CanEnableFieldHelper : DynamicObject
{
   private readonly ICanEnableField _owner;
   
   public CanEnableFieldHelper(ICanEnableField owner)
   {
      _owner = owner;
   }
   
   public override bool TryGetMember(GetMemberBinder binder, out object result)
   {
      result = _owner.CanEnableField(binder.Name);
      return true;
   }
}
 
public class YourViewModel : ICanEnableField
{
   private readonly CanEnableFieldHelper _helper;
   
   public YourViewModel()
   {
      _helper = new CanEnableFieldHelper(this);
   }
   
   public dynamic CanEnable
   {
      get { return _helper; }
   }
   
   public bool CanEnableField(string key)
   {
      ...
   }
}
In you XAML, you can then bind to CanEnable.Key, which will return the result of calling CanEnableField("Key"):
<TextBox IsEnabled="{Binding Path=CanEnable.Field1}" ... />
When you need to change the state, you just need to raise the PropertyChanged event for the CanEnable property.



"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer


GeneralRe: WPF - Bind IsEnabled To Method On VM PinmemberKevin Marois14-Jan-13 10:40 
GeneralRe: WPF - Bind IsEnabled To Method On VM PinmemberKevin Marois20-Jan-13 8:47 
QuestionWPF - Sync Combox [modified] PinmemberKevin Marois12-Jan-13 15:19 
AnswerRe: WPF - Sync Combox PinmemberMycroft Holmes13-Jan-13 0:50 
GeneralRe: WPF - Sync Combox PinmemberKevin Marois13-Jan-13 17:24 
GeneralRe: WPF - Sync Combox PinmemberMycroft Holmes14-Jan-13 0:11 
GeneralRe: WPF - Sync Combox PinmemberKevin Marois14-Jan-13 5:25 
GeneralRe: WPF - Sync Combox PinmemberSledgeHammer0114-Jan-13 9:34 
GeneralRe: WPF - Sync Combox PinmemberKevin Marois23-Jan-13 17:41 
QuestionStyle From Resource File Not Being Applied PinmemberKevin Marois12-Jan-13 10:20 
AnswerRe: Style From Resource File Not Being Applied PinmvpRichard MacCutchan12-Jan-13 23:44 
GeneralRe: Style From Resource File Not Being Applied PinmemberMycroft Holmes13-Jan-13 0:45 
GeneralRe: Style From Resource File Not Being Applied PinmvpRichard MacCutchan13-Jan-13 1:24 
GeneralRe: Style From Resource File Not Being Applied PinmemberKevin Marois13-Jan-13 10:58 
QuestionRoutedEvent vs AttachedEvent - Syntax difference only? Confused [modified] Pinmemberdevvvy9-Jan-13 20:05 
QuestionHow to play an Audio File After another has Finished in WPF MediaElement PinmemberVuyiswa Maseko4-Jan-13 3:58 
AnswerRe: How to play an Audio File After another has Finished in WPF MediaElement PinprotectorPete O'Hanlon4-Jan-13 4:13 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.


Advertise | Privacy | Mobile
Web02 | 2.8.140721.1 | Last Updated 25 Jul 2014
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid