2011-10-27 141 views
0

我嘗試開發WPF頁面時出現問題。我有一個窗口與WPF框架,當窗口加載我使用MainFrame.Navigate(新的頁面對象)。唯一的問題是我不能按任何按鈕或使用文本框。任何想法,我如何解決這個問題?wpf頁面不可編輯

這裏是我的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(); 
} 

我再說一遍,在一個頁面我有文本框和按鈕。但是,當我嘗試使用它們或點擊我可以。事件沒有進入頁面。

在此先感謝

+0

你可以在你處理事件的地方顯示你的代碼嗎? – msarchet

回答

0

嘛!我找出問題的解決方案。

這裏:

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

我將其替換爲:

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

和它工作得很好!

謝謝!

0

你在構造代碼是錯誤的。 它應該被標記爲公開的,而不是私人的。

構造函數將始終調用InitializeComponent,但如果您的構造函數被標記爲private,它將無法正常工作。因此,將顯示控件,但事件句柄不會被執行,因爲事件處理程序代碼在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() });   
} 
+0

嗨!謝謝!構造函數是私人的,因爲我探測使窗口單身。然後我將構造函數更改爲public,但我的工作原理與之前相同。 –