SwiftUI: Get notified when @Binding value changes

Use the onChange modifier instead of onAppear() to watch the textString binding. struct TypewriterTextView: View { @Binding var textString:String @State private var typingInterval = 0.3 @State private var typedString = “” var body: some View { Text(typedString).onChange(of: textString) { typedString = “” Timer.scheduledTimer(withTimeInterval: self.typingInterval, repeats: true, block: { timer in if self.typedString.length < self.textString.length { … Read more

WPF: Reapply DataTemplateSelector when a certain value changes

I found this workaround that seems easier to me. From within the TemplateSelector listen to the property that your care about and then reapply the template selector to force a refresh. public class DataSourceTemplateSelector : DataTemplateSelector { public DataTemplate IA { get; set; } public DataTemplate Dispatcher { get; set; } public DataTemplate Sql { … Read more

how to hide a button that is bound to a command that cannot execute?

You could use a Style and Triggers, assuming that the command is in charge of setting the Button enabled/disabled: <Button x:Name=”btnMoveUp” Command=”{x:Static local:Window1.MoveItemUp}”> <Button.Style> <Style TargetType=”{x:Type Button}” > <Style.Triggers> <Trigger Property=”IsEnabled” Value=”False”> <Setter Property=”Visibility” Value=”Collapsed” /> </Trigger> </Style.Triggers> </Style> </Button.Style> </Button> Note that you can define this Style at a higher scope and share it … Read more

Two Way Binding to AvalonEdit Document Text using MVVM

Create a Behavior class that will attach the TextChanged event and will hook up the dependency property that is bound to the ViewModel. AvalonTextBehavior.cs public sealed class AvalonEditBehaviour : Behavior<TextEditor> { public static readonly DependencyProperty GiveMeTheTextProperty = DependencyProperty.Register(“GiveMeTheText”, typeof(string), typeof(AvalonEditBehaviour), new FrameworkPropertyMetadata(default(string), FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, PropertyChangedCallback)); public string GiveMeTheText { get { return (string)GetValue(GiveMeTheTextProperty); } set { … Read more

Difference between {Binding PropertyName} and {Binding Path=PropertyName}

There is a significant difference here which you will run into as soon as you have a complex property path with typed parameters. Conceptually they are equivalent as they both end up setting the Binding.Path, one via the parameterized Binding constructor, the other directly via the property. What happens internally is very different though as … Read more

WPF event binding from View to ViewModel?

One way to handle events in MVVM and XAML is to use the Blend Interactivity features. This namespace contains the InvokeCommandAction and the CallMethodAction classes. InvokeCommandAction lets you bind any event to a view-model command while CallMethodAction lets you bind any event to a view-model method. For example if you want to bind the DoubleClick … Read more