MVVM pattern violation: MediaElement.Play()

1) Do not call Play() from the view model. Raise an event in the view model instead (for instance PlayRequested) and listen to this event in the view: view model: public event EventHandler PlayRequested; … if (this.PlayRequested != null) { this.PlayRequested(this, EventArgs.Empty); } view: ViewModel vm = new ViewModel(); this.DataContext = vm; vm.PlayRequested += (sender, … Read more

Bind visibility property to a variable

You don’t need to make any converter. Add a binding to a Visibility property for the border: <Border x:Name=”Border1″ Visibility=”{Binding Visibility}” BorderBrush=”Black” BorderThickness=”1″ HorizontalAlignment=”Left” Height=”21″ Margin=”229,164,0,0″ VerticalAlignment=”Top” Width=”90″ Opacity=”0.5″> <Grid> <Label Content=”test”/> </Grid> </Border> And then create the Visibility property in your ViewModel: private Visibility visibility; public Visibility Visibility { get { return visibility; } … Read more

Strange behavior when overriding private methods

Inheriting/overriding private methods In PHP, methods (including private ones) in the subclasses are either: Copied; the scope of the original function is maintained. Replaced (“overridden”, if you want). You can see this with this code: <?php class A { //calling B::h, because static:: resolves to B:: function callH() { static::h(); } private function h() { … Read more

Package protected alternative in Kotlin

Kotlin, compared to Java, seems to rely on packages model to a lesser degree (e.g. directories structure is not bound to packages). Instead, Kotlin offers internal visibility, which is designed for modular project architecture. Using it, you can encapsulate a part of your code inside a separate module. So, on top level declarations you can … Read more

Calling the base class constructor from the derived class constructor

The constructor of PetStore will call a constructor of Farm; there’s no way you can prevent it. If you do nothing (as you’ve done), it will call the default constructor (Farm()); if you need to pass arguments, you’ll have to specify the base class in the initializer list: PetStore::PetStore() : Farm( neededArgument ) , idF( … Read more