2015-10-18 66 views
0

嗨,我是新的C#WPF我创建一个图制作应用程序。它只能保存为.xml文件,以便能够再次编辑,但我想保存它也作为图像,我搜索,但他们正在使用OpenFileDialog和C#WPF不支持OpenFileDialog命令。我有一个这样的代码保存。如何将图像保存在WPF应用程序在C#

<Button Margin="1" Padding="2" HorizontalContentAlignment="Left" 
         Style="{StaticResource ToolBarButtonBaseStyle}" 
         Command="{x:Static ApplicationCommands.Save}" 
         CommandTarget="{Binding ElementName=MyDesigner}"> 
        <Button.Content> 
         <Grid> 
          <Grid.ColumnDefinitions> 
           <ColumnDefinition/> 
           <ColumnDefinition /> 
          </Grid.ColumnDefinitions> 
          <Image Source="Images/image.png" Width="16"/> 
          <TextBlock Margin="3,0,3,0" Text="Save" VerticalAlignment="Center" Grid.Column="1"/> 
         </Grid> 
        </Button.Content> 
       </Button> 

我该怎么办?任何想法将不胜感激。 :)

回答

1

WPF已打开文件对话框... 在usings:

using Microsoft.Win32; 

样品:

OpenFileDialog opf = new OpenFileDialog(); 
if (opf.ShowDialog().HasValue) 
{ 
    string myFile = opf.FileName; 
} 
+0

感谢你非常非常@Spawn,现在我可以完成我的论文计划。我只需要搜索jpg保存代码。 –

+0

保存图像的好例子可以在这里找到,例如 - http://stackoverflow.com/a/4161485/1979354 – Spawn

相关问题