2013-06-17 2 views
0

나는 WindowPage 있습니다. Window에는 기본적으로 사용하지 않는 3 개의 버튼이 있습니다. Page에는 버튼을 하나 클릭하여 10 번 클릭하면 메시지가 표시되고 Window의 버튼을 사용하도록 설정해야합니다.WPF vb.net 클릭 이벤트가 발생한 후 창 활성화 버튼에 페이지

Page 버튼을 10 번 클릭 한 후 어떻게 3 개의 버튼을 활성화 했습니까?

MainWindow를 XAML :

<Window x:Class="MainWindow" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    Title="MainWindow" Height="350" Width="525"> 
    <Grid x:Name="Window1Grid"> 
     <Grid x:Name="FrameGrid"> 
      <Button IsEnabled="False" Content="Button" Height="23" HorizontalAlignment="Left" Margin="18,56,0,0" Name="Button1" VerticalAlignment="Top" Width="75" /> 
      <Button IsEnabled="False" Content="Button" Height="23" HorizontalAlignment="Left" Margin="18,112,0,0" Name="Button2" VerticalAlignment="Top" Width="75" /> 
      <Button IsEnabled="False" Content="Button" Height="23" HorizontalAlignment="Left" Margin="18,165,0,0" Name="Button3" VerticalAlignment="Top" Width="75" /> 
     </Grid> 
     <Frame Source="Page1.xaml" Height="250" HorizontalAlignment="Left" Margin="114,38,0,0" Name="Frame1" VerticalAlignment="Top" Width="300" /> 

    </Grid> 
</Window> 

MainWindow를

된 .vb
Public Class MainWindow 

End Class 

페이지 1 .Xaml

<Page x:Class="Page1" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
    mc:Ignorable="d" 
    d:DesignHeight="250" d:DesignWidth="300" 
    Title="Page1"> 
<Grid x:Name="Page1Grid" Background="Red"> 
    <Button Content="Button" Height="23" HorizontalAlignment="Left" Margin="113,166,0,0" Name="Button1" VerticalAlignment="Top" Width="75" /> 
    <TextBlock Height="23" HorizontalAlignment="Left" Margin="14,12,0,0" Name="Page1TxtBlock" Text="Page1" VerticalAlignment="Top" /> 
</Grid> 

1 페이지 된 .vb

,691,363 (210)
Class Page1 
Dim clicks As String 
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles Button1.Click 
    Try 


     clicks += 1 

     If clicks >= 10 Then 
      MessageBox.Show("Window Buttons should be enabled") 
      clicks = 0 

     End If 
    Catch ex As Exception 

    End Try 
End Sub 

End Class 
+0

후 관련 코드와 XAML을 사용하여 PAGE1에서프레임 사용 페이지를 초기화

Dim p As New Page1(Me) frame.Content = p 

전화를. 또한 대신'Window.ShowDialog()'를 사용할 수도 있습니다. –

+0

자식 (페이지)이 프레임을 통과하기 때문에 작동하지 않습니다. –

+0

관련 코드와 XAML을 게시하십시오. 당신의 설명은 상황을 잘 설명하지 못합니다. 부모 창과 자식 창이 있다고 말하면서 질문을 시작하지만, 이제는 자식 창이 아니라 페이지라는 것을 완전히 다른 것으로 말합니다. –

답변

1

편집 주석의 요청으로

부모 버튼을 클릭에서 귀하의 페이지 1 클래스에 세 개의 버튼을

을 해제 :

Dim parentWindow as MainWindow; 다음 페이지 생성자를 오버로드 :

Public Sub New(ByVal mw As MainWindow) 
    parentWindow=mw 
End Sub 
parentWindow.btnSomethinf.IsEnabled=true... 
+0

이것을 VB로 번역 (죄송합니다)하면 제대로 작동합니다. 그러나 ParentWindow.btn1.IsEnabled (MainWindow.Button1.IsEnabled)를 Page 1 단추에 넣었을 때조차도 "비공유 구성원에 대한 참조 ..."를 얻습니다. 총 신참입니다. 오버로드 페이지 생성자는 어디에 두겠습니까? 내 Page Page1이 명명되고 ParentWindow의 이름이 MainWindow입니다. 감사. –

+0

페이지 생성자가 다음과 같이 오버로드됩니다. Public Sub Page1 (ByVal MainWindow) End Sub correct? –

+1

답변을 편집했습니다. –

관련 문제