2010-01-11 14 views
0

我遇到了一個問題,在運行時和Expression Blend中可見,我的佈局網格中的文本塊(不是文本框,按鈕或自定義控件)不斷推動他們自己在他們的細胞外面,使他們看不見。如果我在Blend中觸摸它們的任何屬性(例如遞增和遞減其中一個邊距),它們在Blend中變得可見,但仍然不在運行時。以下是顯示Blend中現象的截圖。您會看到設計指南指向控件的位置,但它的實際位置位於畫布頂部之上。XAML控件抵消自己,在Blend和瀏覽器中變得不可見

Controls are offset in Blend http://tinyurl.com/y9ttscf

更新: 在下面,我張貼的XAML,與VisualStateGroups刪除(因爲它們增加了相當複雜的XAML和問題表現沒有他們)。上面選擇的控件是下面的「loginTextBlock」。

<navigation:Page 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
    xmlns:navigation="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Navigation" 
    mc:Ignorable="d" xmlns:UserControls="clr-namespace:MyClient.UserControls" xmlns:MyClient_Controls="clr-namespace:MyClient.Controls;assembly=MyClient.Controls" xmlns:controlsToolkit="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Toolkit" x:Class="MyClient.Views.Login" 
    d:DesignWidth="640" d:DesignHeight="480" 
    Title="Login" 
    > 

    <Grid x:Name="LayoutRoot"> 
     <Grid HorizontalAlignment="Center" Margin="0,16,0,0" VerticalAlignment="Top"> 
      <Grid.RowDefinitions> 
       <RowDefinition Height="Auto"/> 
       <RowDefinition Height="Auto"/> 
       <RowDefinition Height="Auto"/> 
       <RowDefinition Height="Auto"/> 
       <RowDefinition Height="Auto"/> 
       <RowDefinition Height="Auto"/> 
      </Grid.RowDefinitions> 
      <Grid.ColumnDefinitions> 
       <ColumnDefinition Width="Auto"/> 
       <ColumnDefinition Width="Auto"/> 
      </Grid.ColumnDefinitions> 
      <TextBlock x:Name="loginTextBlock" HorizontalAlignment="Center" Style="{StaticResource HeaderTextStyle}" VerticalAlignment="Center" Text="Login" Grid.ColumnSpan="2" Margin="0,8"/> 
      <TextBlock x:Name="usernameTextBlock" HorizontalAlignment="Right" VerticalAlignment="Center" Grid.Row="1" Text="User name:" TextWrapping="Wrap"/> 
      <TextBox x:Name="usernameTextBox" HorizontalAlignment="Left" Margin="8,8,0,8" VerticalAlignment="Center" Width="175" Grid.Column="1" Grid.Row="1" TextWrapping="Wrap" TabIndex="0" FontSize="16" Height="28" Padding="2"/> 
      <TextBlock x:Name="passwordTextBlock" HorizontalAlignment="Right" VerticalAlignment="Center" Grid.Row="2" Text="Password:" TextWrapping="Wrap"/> 
      <PasswordBox x:Name="passwordBox" HorizontalAlignment="Left" Margin="8,8,0,8" VerticalAlignment="Center" Width="175" Grid.Column="1" Grid.Row="2" TabIndex="1" FontSize="16" Height="28" Padding="2"/> 
      <Button x:Name="okButton" Height="32" HorizontalAlignment="Center" Margin="0,16,0,0" VerticalAlignment="Top" Width="96" Content="OK" Grid.Row="3" TabIndex="2" Click="okButton_Click" Grid.ColumnSpan="2"/> 
      <UserControls:StatusTextBlockControl x:Name="verifyingStatusTextBlockControl" Margin="8,16,8,8" VerticalAlignment="Center" Grid.Row="4" HorizontalAlignment="Center" Grid.ColumnSpan="2" Text="Verifying credentials..."/> 
      <MyClient_Controls:LoginAttemptsCounter x:Name="loginAttemptsCounter" HorizontalAlignment="Center" Margin="8" VerticalAlignment="Center" Grid.ColumnSpan="2" Grid.Row="5" FirstFailureMessage="Please re-enter your Windows credentials.&#x0a;After 2 more failed attempts, your account will be locked." Height="30"/> 
     </Grid> 

    </Grid> 

</navigation:Page> 

回答

0

出於某種原因,當我的「LoginAttemptsCounter」控制在網格(底部),它被搞亂了TextBlock的控制。相反,我改變了我的佈局以將網格包裝在StackPanel中,並將LoginAttemptsCounter放置在網格下方的StackPanel中,而不是網格的底部行中。這一直奏效。

關鍵是我的自定義控件不能與TextBlocks在同一個容器(StackPanel或Grid)中。

相關問題