I have problem with DataTrigger which work only once.
Button 'btnLokaty' fired Storyboard 'PlikZLokatamiStory' only first time during running program.
I've installed 'PropertyChanged.Fody' in my project and it's work fine. Property 'PlikZLokatamiFileNameCheck' work correctly. Checkbox 'test' show value of 'PlikZLokatamiFileNameCheck'.
Can anyone help me resolve problem? Many thx
Best regards
XAML
<Window x:Class="LokatyNegocjowane.View.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:vm="clr-namespace:LokatyNegocjowane.Viemodel"
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
mc:Ignorable="d"
x:Name="wndMain" Title="MainWindow" Height="600" Width="800" WindowStyle="None" WindowStartupLocation="CenterScreen">
<Window.Resources>
<Storyboard x:Key="PlikZLokatamiStory">
<ThicknessAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.Margin)" Storyboard.TargetName="btnLokaty">
<EasingThicknessKeyFrame KeyTime="0" Value="0,0,10,0"/>
<EasingThicknessKeyFrame KeyTime="0:0:1" Value="-100,0,10,0"/>
</ThicknessAnimationUsingKeyFrames>
</Storyboard>
<Storyboard x:Key="ControlOpacity">
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)">
<EasingDoubleKeyFrame KeyTime="0" Value="0"/>
<EasingDoubleKeyFrame KeyTime="0:0:1" Value="1"/>
</DoubleAnimationUsingKeyFrames>
</Storyboard>
<Storyboard x:Key="PlikZLokatamiStoryBack">
<ThicknessAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.Margin)" Storyboard.Target="{x:Reference btnLokaty}">
<EasingThicknessKeyFrame KeyTime="0" Value="-100,0,10,0"/>
<EasingThicknessKeyFrame KeyTime="0:0:1" Value="0,0,10,0"/>
</ThicknessAnimationUsingKeyFrames>
</Storyboard>
<Storyboard x:Key="ControlOpacityBack">
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)">
<EasingDoubleKeyFrame KeyTime="0" Value="1"/>
<EasingDoubleKeyFrame KeyTime="0:0:1" Value="0"/>
</DoubleAnimationUsingKeyFrames>
</Storyboard>
</Window.Resources>
<Window.DataContext>
<vm:ViewModel/>
</Window.DataContext>
<Grid Background="#FF3580BF">
<StackPanel Height="150" VerticalAlignment="Top">
<Image Height="150" Source="..\Resources\baner.jpg" HorizontalAlignment="Center" Stretch="Fill"/>
</StackPanel>
<StackPanel>
<CheckBox x:Name="test" IsChecked="{Binding PlikZLokatamiFileNameCheck}" Margin="0 150"/>
</StackPanel>
<StackPanel x:Name="StackPanelMenu" Width="600" HorizontalAlignment="Center" Margin="0 180 0 0">
<StackPanel x:Name="spLokaty" VerticalAlignment="Center" Orientation="Horizontal" Height="60">
<StackPanel.Style>
<Style TargetType="{x:Type StackPanel}">
<Style.Triggers>
<Trigger Property="Control.IsMouseOver" Value="True">
<Setter Property="Background" Value="#557080BF"/>
<Setter Property="Opacity" Value="5"/>
</Trigger>
</Style.Triggers>
</Style>
</StackPanel.Style>
<StackPanel x:Name="spPlikZLokatami" VerticalAlignment="Center" Margin="250 0 10 0">
<Button x:Name="btnLokaty" Background="Transparent" HorizontalAlignment="Center" BorderThickness="0" Command="{Binding WybierzPlikZLokatami}" Foreground="White">
<Button.Style>
<Style TargetType="{x:Type Button}">
<Style.Triggers>
<DataTrigger Binding="{Binding PlikZLokatamiFileNameCheck}" Value="True">
<DataTrigger.EnterActions>
<BeginStoryboard Storyboard="{StaticResource PlikZLokatamiStory}"/>
</DataTrigger.EnterActions>
</DataTrigger>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Cursor" Value="Hand"/>
<Setter Property="Background" Value="Transparent"/>
</Trigger>
</Style.Triggers>
</Style>
</Button.Style>
<StackPanel Orientation="Horizontal" VerticalAlignment="Center">
<materialDesign:PackIcon Kind="File" Width="20" Height="20" VerticalAlignment="Center"/>
<TextBlock Text="Plik z lokatami" FontSize="10" VerticalAlignment="Center"/>
</StackPanel>
</Button>
</StackPanel>
<StackPanel x:Name="spFileName" VerticalAlignment="Center" Orientation="Horizontal">
<TextBlock x:Name="tbLokaty" Foreground="White" Text="{Binding PlikZLokatamiFileName}" Opacity="0">
<TextBlock.Style>
<Style>
<Style.Triggers>
<DataTrigger Binding="{Binding PlikZLokatamiFileNameCheck}" Value="True">
<DataTrigger.EnterActions>
<BeginStoryboard Storyboard="{StaticResource ControlOpacity}"/>
</DataTrigger.EnterActions>
</DataTrigger>
</Style.Triggers>
</Style>
</TextBlock.Style>
</TextBlock>
<Button Background="Transparent" BorderBrush="{x:Null}" Opacity="0" Command="{Binding UsunPlikLokat}">
<Button.Style>
<Style TargetType="{x:Type Button}">
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Cursor" Value="Hand"/>
</Trigger>
<DataTrigger Binding="{Binding PlikZLokatamiFileNameCheck}" Value="True">
<DataTrigger.EnterActions>
<BeginStoryboard Storyboard="{StaticResource ControlOpacity}"/>
</DataTrigger.EnterActions>
</DataTrigger>
</Style.Triggers>
</Style>
</Button.Style>
<Button.Triggers>
<EventTrigger RoutedEvent="Button.Click">
<BeginStoryboard Storyboard="{StaticResource PlikZLokatamiStoryBack}"/>
<BeginStoryboard Storyboard="{StaticResource ControlOpacityBack}"/>
</EventTrigger>
</Button.Triggers>
<materialDesign:PackIcon Kind="RemoveCircle" Foreground="Red"/>
</Button>
</StackPanel>
</StackPanel>
<ListView Height="60">
<Button Background="Transparent" BorderThickness="0" Command="{Binding WybierzPlikZWnioskami}">
<Button.Content>
<StackPanel Orientation="Horizontal" VerticalAlignment="Center">
<materialDesign:PackIcon Kind="File" Width="20" Height="20" VerticalAlignment="Center"/>
<TextBlock Text="Plik z wnioskami" FontSize="10" VerticalAlignment="Center"/>
</StackPanel>
</Button.Content>
</Button>
</ListView>
<ListView Height="50">
<Button Background="Transparent" BorderThickness="0" Command="{Binding WybierzPlikZPracownikamiBOKZ}">
<Button.Content>
<StackPanel Orientation="Horizontal" VerticalAlignment="Center">
<materialDesign:PackIcon Kind="Worker" Width="20" Height="20" VerticalAlignment="Center"/>
<TextBlock Text="Pracownicy BOKZ" FontSize="10" VerticalAlignment="Center"/>
</StackPanel>
</Button.Content>
</Button>
</ListView>
<ListView Height="60">
<Button Background="Transparent" BorderThickness="0" Command="{Binding WyjdzCommand}">
<Button.Content>
<StackPanel Orientation="Horizontal" VerticalAlignment="Center">
<materialDesign:PackIcon Kind="ExitToApp" Width="20" Height="20" VerticalAlignment="Center"/>
<TextBlock Text="Wyście" FontSize="10" VerticalAlignment="Center"/>
</StackPanel>
</Button.Content>
</Button>
</ListView>
</StackPanel>
<StackPanel x:Name="stackPanel" Orientation="Horizontal" VerticalAlignment="Top" Height="40" HorizontalAlignment="Left" Margin="0 150">
<Button x:Name="btnZamknijMenu" ToolTip="Zamknij menu" Width="30" Height="30" Padding="0" Visibility="Collapsed" Background="{x:Null}" BorderBrush="{x:Null}">
<materialDesign:PackIcon Kind="Menu"/>
<Button.Triggers>
<EventTrigger RoutedEvent="Button.Click">
<BeginStoryboard Storyboard="{StaticResource ZamknijMenu}"/>
</EventTrigger>
</Button.Triggers>
</Button>
</StackPanel>
<StackPanel>
<Button Content="START" Margin="200, 450" Height="50" Command="{Binding Start}"/>
</StackPanel>
</Grid>
My ViewModel
using GalaSoft.MvvmLight.Command;
using Microsoft.Win32;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Input;
namespace LokatyNegocjowane.Viemodel
{
public class ViewModel : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
private string plikZLokatamiFullPath;
private string plikZWnioskamiFullPath;
private string plikZPracownikamiBOKZFullPath;
public ICommand WyjdzCommand { get; set; }
public ICommand WybierzPlikZLokatami { get; set; }
public ICommand WybierzPlikZWnioskami { get; set; }
public ICommand WybierzPlikZPracownikamiBOKZ { get; set; }
public ICommand Start { get; set; }
public ICommand UsunPlikLokat { get; set; }
public string PlikZWnioskamiFileName { get; set; }
public string PlikZPracownikamiBOKZFileName { get; set; }
public Boolean PlikZLokatamiFileNameCheck { get; set; }
public string PlikZLokatamiFileName
{
get
{
return Path.GetFileName(plikZLokatamiFullPath);
}
set
{
plikZLokatamiFullPath = value;
if (value != null && value != "") PlikZLokatamiFileNameCheck = true;
else PlikZLokatamiFileNameCheck = false;
}
}
public ViewModel()
{
WyjdzCommand = new RelayCommand(exitApp);
WybierzPlikZLokatami = new RelayCommand(wybierzPlikZLokatami);
WybierzPlikZWnioskami = new RelayCommand(wybierzPlikZWnioskami);
WybierzPlikZPracownikamiBOKZ = new RelayCommand(wybierzPlikZPracownikamiBOKZ);
UsunPlikLokat = new RelayCommand(usunPlikLokat);
Start = new RelayCommand(start);
}
private void exitApp()
{
System.Windows.Application.Current.Shutdown();
}
private void wybierzPlikZLokatami()
{
OpenFileDialog open = new OpenFileDialog();
if (open.ShowDialog() == true)
{
plikZLokatamiFullPath = open.FileName;
PlikZLokatamiFileName = Path.GetFileName(open.FileName);
}
//PlikZLokatamiFileNameCheck = true;
}
private void wybierzPlikZWnioskami()
{
OpenFileDialog open = new OpenFileDialog();
if (open.ShowDialog() == true)
{
plikZWnioskamiFullPath = open.FileName;
PlikZWnioskamiFileName = Path.GetFileName(open.FileName);
}
}
private void wybierzPlikZPracownikamiBOKZ()
{
OpenFileDialog open = new OpenFileDialog();
if (open.ShowDialog() == true)
{
plikZPracownikamiBOKZFullPath = open.FileName;
PlikZPracownikamiBOKZFileName = Path.GetFileName(open.FileName);
}
}
private void start()
{
if (walidacja())
MessageBox.Show("OK");
else MessageBox.Show("Brak wymaganych raportów");
}
private Boolean walidacja()
{
if ((plikZLokatamiFullPath != null && plikZLokatamiFullPath != "") && (plikZWnioskamiFullPath != null && plikZWnioskamiFullPath != "") && (plikZPracownikamiBOKZFullPath != null && plikZPracownikamiBOKZFullPath != ""))
return true;
return false;
}
private void usunPlikLokat()
{
PlikZLokatamiFileName = null;
}
}
}