2014-04-13 1 views
0

두 개의 사용자 지정 WPF 명령을 만들려고합니다. 하나는 호출 될 때 Firefox 브라우저를 시작하는 WebBrowser이고 다른 하나는 호출 될 때 간단한 끝내기 명령입니다. 나는 그것을 알아 내려고 노력하는 것을 어지럽 혔지만, 나는 내가 생각한만큼 영리하지 않다고 생각한다. 나는 단지 출구 명령을 알아낼 수 있었다. 내 브라우저를 호출하는 방법을 알아낼 수 없기 때문에 미친 짓입니다. 어떤 도움이라도 대단히 감사하겠습니다. 이것은 내가 지금까지 가지고있는 것이다.파이어 폭스 브라우저를 실행하기 위해 사용자 정의 WPF 명령을 작성하는 방법은 무엇입니까?

XAML 코드 :

<Window x:Class="WpfTutorialSamples.Commands.CustomCommandSample" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:self="clr-namespace:WpfTutorialSamples.Commands" 
    Title="CustomCommandSample" Height="150" Width="200"> 
<Window.CommandBindings> 
    <CommandBinding Command="self:CustomCommands.Exit" CanExecute="ExitCommand_CanExecute" Executed="ExitCommand_Executed" /> 
</Window.CommandBindings> 
<Grid> 
    <Grid.RowDefinitions> 
     <RowDefinition Height="Auto" /> 
     <RowDefinition Height="*" /> 
    </Grid.RowDefinitions> 
    <Menu> 
     <MenuItem Header="File"> 
      <MenuItem Command="self:CustomCommands.Exit" /> 
     </MenuItem> 
    </Menu> 
    <StackPanel Grid.Row="1" HorizontalAlignment="Center" VerticalAlignment="Center"> 
     <Button Command="self:CustomCommands.Exit">Exit</Button> 
    </StackPanel> 
</Grid> 
</Window> 

코드 숨김 :

using System; 
using System.Collections.Generic; 
using System.Windows; 
using System.Windows.Input; 

namespace WpfTutorialSamples.Commands 
{ 
    public partial class CustomCommandSample : Window 
    { 
      public CustomCommandSample() 
      { 
        InitializeComponent(); 
      } 

      private void ExitCommand_CanExecute(object sender, CanExecuteRoutedEventArgs e) 
      { 
        e.CanExecute = true; 
      } 

      private void ExitCommand_Executed(object sender, ExecutedRoutedEventArgs e) 
      { 
        Application.Current.Shutdown(); 
      } 
    } 

    public static class CustomCommands 
    { 
      public static readonly RoutedUICommand Exit = new RoutedUICommand 
        (
          "Exit", 
          "Exit", 
          typeof(CustomCommands), 
          new InputGestureCollection() 
          { 
            new KeyGesture(Key.F4, ModifierKeys.Alt) 
          } 
        ); 
    } 
} 

답변

3

특별히 파이어 폭스를 열고 자하고 당신처럼 뭔가를 할 수 있습니다, 그것은 현재의 보장 한 경우 :

System.Diagnostics.Process.Start(WhereFirefoxIs, SomeUrl); 

URL은 Firefox의 about:blank과 같을 수 있으며 선택 항목 일 수도 있습니다.

실제로 시스템 기본 브라우저에서 URL을 열려면 다소 안전해야하며 Start(SomeUrl)을 입력하고 Windows에서 처리 방법을 결정하게하십시오. 그러나 네트워크 URL이므로 로컬 파일을 실행하지 않도록주의하십시오.

+0

시작 (SomeUrl)을 사용하면 자동으로 기본 브라우저가 열리니까? 또한 새로운 InputGestureCollection으로 입력 할 수 있습니까? – user3316391

+0

예, URL이있는'Start()'는 기본 브라우저로 등록 된 시스템을 가지고 있기 때문에 잘 작동합니다. 최선의 방법은 아마 당신이 "Exit"를 위해 무엇을하고 있는지를 복사하고 당신의'Web_Executed() '핸들러에 코드를 드롭하는 것일 것입니다. –

관련 문제