2010-01-11 34 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)中。

相关问题