2015-10-18 65 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

相關問題