在DataTrigger上遇到问题,它只能工作一次。
在运行程序期间,按钮“ btnLokaty”仅触发了故事板“ PlikZLokatamiStory”。
我已经在项目中安装了“ PropertyChanged.Fody”,并且工作正常。属性“ PlikZLokatamiFileNameCheck”可以正常工作。复选框“测试”显示值为“ PlikZLokatamiFileNameCheck”。
谁能帮我解决问题?多谢
最好的祝福
XAML
<Window.Resources> </Window.Resources> <Window.DataContext> vm:ViewModel/ </Window.DataContext> <StackPanel.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>
我的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;
}
}
}
添加评论 知道谁可以回答?
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。