0

私はWindowとを持っていPageます。にWindowは 3 つのボタンがあり、デフォルトでは無効になっています。にPageは 1 つのボタンがあり、10 回クリックするとメッセージが表示され、 のボタンが有効になりますWindow

ウィンドウ内のボタンをPage10 回クリックした後、ウィンドウ内の 3 つのボタンを有効にするにはどうすればよいですか?

メインウィンドウ 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>

メインウィンドウ .vb

   Public Class MainWindow

End Class

Page1 .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

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
4

1 に答える 1

1

コメントで尋ねられたように編集

親ボタンをクリックすると、3 つのボタンすべてが無効になります

あなたの Page1 クラスで:

Dim parentWindow as MainWindow;

次に、 Page コンストラクターをオーバーロードします。

Public Sub New(ByVal mw As MainWindow)
    parentWindow=mw
End Sub

Page in Frame 使用の初期化時

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

を使用してpage1から呼び出します

parentWindow.btnSomethinf.IsEnabled=true...
于 2013-06-17T18:08:35.727 に答える