I have a view model that inherits from a baseclass that has a property called IsReadOnly. In this view model i have a property called Customer and i'm binding the properties of the customer object to controls on my view.
However i also want to be able to bind the IsReadOnly to each control on my view also.
<TextBox x:Name="FirstNameTextBox" Grid.Column="1" Margin="2,2,0,2" Grid.Row="2" TextWrapping="Wrap" HorizontalAlignment="Left" Width="200"
Text="{Binding FirstName, Mode=TwoWay}" IsReadOnly="{Binding MyViewModel.IsReadOnly}"/>
How can i go about using both these properties? here is my structure
public class MyViewModelBase { public bool IsReadonly { get;set;} }
public class MyViewModel { public Customer Customer { get; set; } }
public class Customer { public string FamilyName { get; set; } }
Cheers for any help
Property traversing works with Binding too, so you can do the following to bind to IsReadonly property of the base object:
public class MyViewModel {
public Customer Customer { get; set; }
}
public class Customer : Entity {
}
public class Entity {
public bool IsReadonly { get;set;}
}
<Button IsEnabled="{Binding Customer.IsReadonly}" />
For the above example, I'm supposing your view is bound to an instance of "MyViewModel" and you probably already have property notification change on your properties.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With