2011-08-27 2 views
0

저는 간단한 WPF 윈도우를 가지고 있습니다. 아주 간단합니다. TextBlockButton입니다. 그러나 버튼이 아무 반응을 보이지 않습니다. 마우스를 움직이거나 클릭하면 안됩니다. 버튼에서WPF 버튼이 어떤 이벤트에도 반응하지 않습니다.

라인 :

<Button Margin="3" Command="Close" Content="Ok" Width="50"/> 

전체 창 코드 : 그것은 모두 당신의 Styles.xaml에 무엇에 따라 달라집니다

<Window x:Class="Launcher.XAML.MessageWindow" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    x:Name="self" 
    Title="{Binding ElementName=self, Path=Caption}" Height="194" Width="477"> 
<Window.Resources> 
    <ResourceDictionary> 
     <ResourceDictionary.MergedDictionaries> 
      <ResourceDictionary Source="Styles.xaml" /> 
     </ResourceDictionary.MergedDictionaries> 
    </ResourceDictionary> 
</Window.Resources> 
<Grid> 
    <Grid.RowDefinitions> 
     <RowDefinition Height="*" /> 
     <RowDefinition Height="Auto" /> 
    </Grid.RowDefinitions> 
    <TextBlock VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Text="{Binding ElementName=self, Path=Message}" Margin="10" TextWrapping="Wrap" /> 

    <StackPanel Grid.Row="1" HorizontalAlignment="Right" Orientation="Horizontal"> 
     <Button Margin="3" Command="Close" Content="Ok" Width="50"/> 
    </StackPanel> 
</Grid> 

+1

그리고 어떻게 반응 할 것으로 예상됩니까? – svick

+0

마우스 오버/클릭과 같은 시각적 변화가있을 수 있습니다. 적어도 그것이 제 가정입니다. –

답변

1

당신은 다음처럼있는 CommandBindings와 버튼을 지정해야합니다

private void CloseCommandHandler(object sender, ExecutedRoutedEventArgs e) 
{ 
    //Do something 
} 

private void CanExecuteHandler(object sender, CanExecuteRoutedEventArgs e) 
{ 
    //Determine whether handler can execute 
    e.CanExecute = true; 
} 

희망이 도움이됩니다.

+0

그래, CanExecute 처리기 .. 또한, 그 standart 명령 wpf 오버 중 하나 그래서 나는 내 자신을 쓸 필요가 있었다. – skeleten

+0

XAML에서'ApplicationCommands.Close'를'Close'로 줄일 수 있습니다. – svick

0

. 그 주석을 주석으로 처리 한 다음 작동하는지 확인하십시오.

0

Close 명령에 바인딩하는 데 문제가있을 수 있습니다. 상황이에 보면 (그리고 아마도 우리에게 보여 일) : 뷰의 DataContext를 제대로 설정되어 있는지

  • 뷰 모델에있는 닫기 속성에서 반환 명령이 구현되는 방법
  • ...

<Window.CommandBindings> 
    <CommandBinding Command="ApplicationCommands.Close" 
       Executed="CloseCommandHandler" 
       CanExecute="CanExecuteHandler" 
       /> 
</Window.CommandBindings> 

.... 

<Button Margin="3" Command="ApplicationCommands.Close" Content="Ok" Width="50"/> 

그리고 설치하여 실행되고 CanExecute 처리기를 :

관련 문제