代码之家  ›  专栏  ›  技术社区  ›  Dov

xaml控件使自己偏移,在blend和browser中变得不可见

  •  0
  • Dov  · 技术社区  · 15 年前

    我遇到了一个问题,在运行时和表达式混合中都是可见的,布局网格中的文本块(而不是文本框、按钮或自定义控件)一直将自己推到单元格外部,使它们不可见。如果我在Blend中触摸它们的任何属性(例如递增,然后递减其中一个边距),它们在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>
    
    1 回复  |  直到 15 年前
        1
  •  0
  •   Dov    15 年前

    出于某种原因,当我的“loginattempsconter”控件在网格中(在底部)时,它弄乱了textblock控件。相反,我更改了布局,将网格包装在stackpanel中,并将loginAttentsCenter放在网格下面的stackpanel中,而不是放在网格的底部行中。这已经奏效了。

    关键是我的自定义控件不能与textblocks在同一个容器(stackpanel或grid)中。