0

我遇到了一个问题,在运行时和 Expression Blend 中可见,其中我的布局网格中的文本块(不是文本框、按钮或自定义控件)不断将它们自己推到它们的单元格之外,使它们不可见。如果我在 Blend 中触摸它们的任何属性(例如递增然后递减其中一个边距),它们在 Blend 中变得可见,但在运行时仍然不可见。下面是一个屏幕截图,显示了 Blend 中的现象。您会看到设计指南指出了控件应该在的位置,但它的实际位置在画布顶部上方。

控件在 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>
4

1 回答 1

0

出于某种原因,当我的“LoginAttemptsCounter”控件在网格中(在底部)时,它弄乱了 TextBlock 控件。相反,我更改了布局,将网格包裹在 StackPanel 中,并将 LoginAttemptsCounter 放在网格下方的 StackPanel 中,而不是放在网格的底行中。那已经奏效了。

关键是我的自定义控件不能与 TextBlocks 在同一个容器(StackPanel 或网格)中。

于 2010-01-12T14:51:22.687 回答