我正在尝试从我的应用程序中的SaveFileDialog
获取文件名。
<Button Content="Raise" Click="Click" Name="btn">
<i:Interaction.Triggers>
<prism:InteractionRequestTrigger SourceObject="{Binding SaveFileRequest, Mode=OneWay}">
<library:ShowSaveDialogAction/>
</prism:InteractionRequestTrigger>
</i:Interaction.Triggers>
</Button>
这是我的ShowSaveDialogAction
:
public class ShowSaveDialogAction : TriggerAction<FrameworkElement>
{
public string FileName
{
get { return (string)GetValue(FileNameProperty); }
set { SetValue(FileNameProperty, value); }
}
public static readonly DependencyProperty FileNameProperty = DependencyProperty.Register("FileName", typeof(string), typeof(ShowSaveDialogAction), new PropertyMetadata(""));
protected override void Invoke(object o)
{
SaveFileDialog sfd = new SaveFileDialog();
if (sfd.ShowDialog() == true)
{
FileName = sfd.FileName;
}
}
}
这是我的XAML背后的代码:
public partial class Shell : Window
{
public Shell()
{
InitializeComponent();
SaveFileRequest = new InteractionRequest<ISaveConfirmation>();
this.DataContext = this;
}
public InteractionRequest<ISaveConfirmation> SaveFileRequest { get; set; }
private void Click( object sender, RoutedEventArgs e )
{
SaveFileRequest.Raise( new SaveConfirmation { Title = "" }, OnAnswer );
}
private void OnAnswer( ISaveConfirmation obj )
{
if (obj.Confirmed)
{
btn.Content = obj.FileName;
}
}
}
所以我不知道接下来该做什么,以及如何在按钮上的对话框中显示文件名。我如何将所有东西连接在一起?