I am new to WPF and even new to MVVM. I created 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 follows this button, I want a simple popup to appear.
MainWindowViewModel -> I created a property (popupstatus) that I would use as a trigger for the mouseover event handler.
MyPopUp.xaml β In this view, I set the details. I want to use a property from MainWindowViewModel to run if it should appear or not.
But even after all this, I have two problems: one, I canβt use the animation for the property that I created in my MainWindowViewModel in the MainWindow.xaml file. I get the message "Cannot resolve all property references in the property path of" PopUpStatus "., Other - I cannot bind to this propety in my pop-up code.
In the end, I want to have a viewmodel for a popup that will do more advanced things.
Thank you 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>
source
share