Setting the Visibility of an Element to Collapsed when Storyboard completes using XAML

you can do this in the animation as well <Window.Resources> <Storyboard x:Key=”OnLoaded1″> <ObjectAnimationUsingKeyFrames BeginTime=”00:00:00″ Storyboard.TargetName=”button” Storyboard.TargetProperty=”(UIElement.Visibility)”> <DiscreteObjectKeyFrame KeyTime=”00:00:00″ Value=”{x:Static Visibility.Visible}”/> <DiscreteObjectKeyFrame KeyTime=”00:00:00.8000000″ Value=”{x:Static Visibility.Collapsed}”/> <DiscreteObjectKeyFrame KeyTime=”00:00:01.4000000″ Value=”{x:Static Visibility.Visible}”/> </ObjectAnimationUsingKeyFrames> </Storyboard> </Window.Resources> <Window.Triggers> <EventTrigger RoutedEvent=”FrameworkElement.Loaded”> <BeginStoryboard Storyboard=”{StaticResource OnLoaded1}”/> </EventTrigger> </Window.Triggers>

Binding [VisualStateManager] view state to a MVVM viewmodel?

Actually you can. The trick is to make an Attached property and add a property changed callback that actually calls GoToState: public class StateHelper { public static readonly DependencyProperty StateProperty = DependencyProperty.RegisterAttached( “State”, typeof( String ), typeof( StateHelper ), new UIPropertyMetadata( null, StateChanged ) ); internal static void StateChanged( DependencyObject target, DependencyPropertyChangedEventArgs args ) { … Read more

A better way of forcing data bound WPF ListBox to update?

I have a Listbox bound to an object property which is of type List<MyCustomType>() and I verified that the following code updates the listbox when the List is updated. void On_MyObjProperty_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e) { MyListBox.Items.Refresh(); } If you’re still facing issues, scan the VS IDE output window (Ctrl+W, O) and see if you can … Read more

WPF Context menu on left click

Here is a XAML only solution. Just add this style to your button. This will cause the context menu to open on both left and right click. Enjoy! <Button Content=”Open Context Menu”> <Button.Style> <Style TargetType=”{x:Type Button}”> <Style.Triggers> <EventTrigger RoutedEvent=”Click”> <EventTrigger.Actions> <BeginStoryboard> <Storyboard> <BooleanAnimationUsingKeyFrames Storyboard.TargetProperty=”ContextMenu.IsOpen”> <DiscreteBooleanKeyFrame KeyTime=”0:0:0″ Value=”True”/> </BooleanAnimationUsingKeyFrames> </Storyboard> </BeginStoryboard> </EventTrigger.Actions> </EventTrigger> </Style.Triggers> <Setter Property=”ContextMenu”> … Read more

Cannot see _ (underscore) in WPF content

Labels support mnemonics (i.e. you can use ctrl+(key) to give them focus). You define the mnemonic key using an underscore. http://www.charlespetzold.com/blog/2006/01/061004.html If you want to see underscores, replace single underscores with double underscores.