I am new to WPF and even newer to MVVM. I have set up a simple application to try to understand WPPF. In my application I have the following:
MainWindow.xaml -> I have a button. I want if the mouse goes over this button I want to have a simple popup show up.
MainWindowViewModel -> I have created a property (popupstatus) which I would use as a trigger for my mouseover event handler.
MyPopUp.xaml -> In this view I have set up the popup details. I want to use the property from MainWindowViewModel to trigger if it should show up or not.
But even after all this I have having two problems: One I cannot seem to use animation for the property I created in my MainWindowViewModel in my MainWindow.xaml file. I get an "Cannot resolve all property references in the property path 'PopUpStatus'." . The other is I can't bind to this propety in my pop up code either.
Eventually I want to have a viewmodel for popup which will do some more advanced stuff.
Thanks for your help :)
MainWindow.xaml:
<Button.Triggers>
<EventTrigger RoutedEvent="MouseEnter">
<EventTrigger.Actions>
<BeginStoryboard>
<Storyboard>
<BooleanAnimationUsingKeyFrames Storyboard.Target="{Binding .}" Storyboard.TargetProperty="PopUpStatus">
<DiscreteBooleanKeyFrame Value="True" KeyTime="0:0:2"/>
</BooleanAnimationUsingKeyFrames>
</Storyboard>
</BeginStoryboard>
</EventTrigger.Actions>
</EventTrigger>
<EventTrigger RoutedEvent="MouseLeave">
<EventTrigger.Actions>
<BeginStoryboard>
<Storyboard>
<BooleanAnimationUsingKeyFrames Storyboard.TargetName="FiberPopUp" Storyboard.TargetProperty="IsOpen">
<DiscreteBooleanKeyFrame Value="False" KeyTime="0:0:2"/>
</BooleanAnimationUsingKeyFrames>
</Storyboard>
</BeginStoryboard>
</EventTrigger.Actions>
</EventTrigger>
</Button.Triggers>
</Button>
</Grid>
MainWindowViewModel: private bool _PopUpStatus = false; public MainWindowViewModel() { }
public bool PopUpStatus
{
get
{
return _PopUpStatus;
}
set
{
_PopUpStatus = value;
RaisePropertyChanged("PopUpStatus");
}
}
public event PropertyChangedEventHandler PropertyChanged;
protected void RaisePropertyChanged(string name)
{
PropertyChangedEventHandler handler = PropertyChanged;
if (handler != null) handler(this, new PropertyChangedEventArgs(name));
}
myPopUp.xaml -->
<StackPanel Width="auto" Height="auto" >
<TextBlock Background="White" Foreground="Black" Text="This is a test."/>
<Button Content="ClosePopUp" Click="PopUpClose" />
</StackPanel>
</Popup>
</Grid>