在单击页面上的事件后使窗口上的按钮启用
本文关键字:窗口 按钮 启用 事件 单击 | 更新日期: 2023-09-27 18:18:57
我有一个Window
和一个Page
。Window
有3个按钮,默认禁用。Page
有1个按钮,当点击10次时显示一条消息,并且应该启用Window
上的按钮。
在Page
中的按钮被点击10次后,我如何启用窗口中的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
按注释中的要求编辑
点击父按钮禁用所有三个按钮
在你的Page1类中:
Dim parentWindow as MainWindow;
然后重载页面构造函数:
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...