【问题标题】:wpf page not editablewpf页面不可编辑
【发布时间】:2011-10-27 17:41:11
【问题描述】:

我在尝试开发 WPF 页面时遇到问题。我有一个带有 WPF 框架的窗口,当加载窗口时,我使用 MainFrame.Navigate(新页面对象)。唯一的问题是我不能按任何按钮或使用文本框。任何想法,我该如何解决这个问题?

这是我的 wpf 窗口的代码:

<Window x:Class="ViewLayer.Forms.Win_LoginCloseable"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="Win_LoginCloseable" Height="477" Width="501" WindowStyle="None" WindowStartupLocation="CenterScreen" ResizeMode="NoResize">
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="180*" />
            <RowDefinition Height="164*" />
            <RowDefinition Height="35*" />
        </Grid.RowDefinitions>
        <Rectangle Grid.RowSpan="3"  Name="Rect_Main" />
        <TextBlock Grid.Row="2" FontFamily="Calibri" FontSize="17" FontStyle="Italic" Margin="10,0,12,7" Name="tb_remainding" Text="" TextAlignment="Justify" TextWrapping="WrapWithOverflow" Height="28" VerticalAlignment="Bottom" />
        <Button Content="Cerrrar" Grid.Row="1" Height="73" HorizontalAlignment="Center" Name="btn_cancel" VerticalAlignment="Bottom" Width="173" Click="btn_cancel_Click" Background="#FFC70000" Margin="114,0,114,5" />
            <Frame x:Name="MainFrame" IsHitTestVisible="False" NavigationUIVisibility="Automatic" />
        <TextBlock FontFamily="Calibri" FontSize="22" FontWeight="Bold" Foreground="#FF797979" Height="95" Margin="0,0,0,0" Name="textBlock2" Text="Una vez identificado, luego de 90 segundos de inactividad el sistema cerrará su sesión automaticamente" TextAlignment="Center" TextTrimming="None" TextWrapping="Wrap" VerticalAlignment="Top" Grid.Row="1" HorizontalAlignment="Center" />
        <TextBox Grid.Row="1" Height="23" HorizontalAlignment="Left" Margin="34,100,0,0" Name="textBox1" VerticalAlignment="Top" Width="120" />
    </Grid>
</Window>

窗口的构造函数

private Win_LoginCloseable()
        {
            InitializeComponent();
            this.Pages = new List<Page>();
            this.Pages.AddRange(new Page[]{
                    new MagneticCardPage(),
                    new UserInputPage()
                });

        }

当我加载表单时:

public void LoadForm(int Index = 0)
{
this.MainFrame.Navigate(this.Pages[Index]);
this.ShowDialog();
}

我重复一遍,在一个页面中我有文本框和按钮。但是当我尝试使用它们或单击时,我可以。事件没有到达页面。

提前致谢

【问题讨论】:

  • 你能在你处理事件的地方显示你的代码吗?

标签: c# wpf


【解决方案1】:

构造函数中的代码是错误的。 应将其标记为公开,而不是私有。

构造函数总是会调用InitializeComponent,但是如果你的构造函数被标记为私有,它就不能正常工作。因此,控件将被显示,但事件句柄不会被执行,因为事件处理程序代码在 InitializeComponent 中是可用的,我确定它不会被执行。

改变这个:

private Win_LoginCloseable()         
{
    InitializeComponent();
    this.Pages = new List<Page>();
    this.Pages.AddRange(new Page[]{                     
        new MagneticCardPage(),                     
        new UserInputPage() });          
} 

进入这个:

public Win_LoginCloseable()         
{
    InitializeComponent();
    this.Pages = new List<Page>();
    this.Pages.AddRange(new Page[]{                     
        new MagneticCardPage(),                     
        new UserInputPage() });          
} 

【讨论】:

  • 嗨!谢谢!构造函数是私有的,因为我探测使窗口单例。然后我将构造函数更改为公共,但我的工作方式与以前相同。
【解决方案2】:

好吧!我想出了问题的解决方案。

这里:

<Frame x:Name="MainFrame" IsHitTestVisible="False" NavigationUIVisibility="Automatic" />

我将其替换为:

<Frame x:Name="MainFrame" IsManipulationEnabled="True" />

而且效果很好!

谢谢!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-02-16
    • 2014-10-10
    • 1970-01-01
    • 2012-03-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多