<;视图:内容>;XAML中的标记

本文关键字:XAML 内容 lt 视图 gt | 更新日期: 2023-09-27 17:57:49

我继承了一些代码,我在几个位置看到了这种构造,但我不习惯:

    <view:Content x:Name="TimeFrame" Margin="220,50,0,0" VerticalAlignment="Top" HorizontalAlignment="Left" >
        <view:Content.ChildContent>
            <view:TimeFrame />
        </view:Content.ChildContent>
    </view:Content>

我必须承认,这看起来相当漂亮,而且到目前为止,它也符合我的要求。然而,在这种情况下,中心没有<view:TimeFrame />-标签,而是有一个常规的控制标签,如下所示:

    <view:Content x:Name="SignInControl" Margin="466,317,0,0" HorizontalAlignment="Left" Width="348" Height="344" VerticalAlignment="Top">
        <view:Content.ChildContent>
            <Grid>
                <Border  CornerRadius="8,8,0,0" BorderThickness="1" Width="270" Height="300" Background="#666666" Margin="1,0,-1,0" Opacity="0.57"  >
                    <Border.Effect>
                        <BlurEffect/>
                    </Border.Effect>
                </Border>
                <Border  CornerRadius="8,8,0,0" BorderThickness="1" Width="270" Height="300" Background="#FFF3F5F4">
                    <Grid>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="15"/>
                            <RowDefinition Height="100"/>
                            <RowDefinition Height="25"/>
                            <RowDefinition Height="40"/>
                            <RowDefinition Height="40"/>
                            <RowDefinition Height="20"/>
                            <RowDefinition Height="20"/>
                            <RowDefinition Height="auto"/>
                        </Grid.RowDefinitions>
                        <TextBlock Grid.Row="0" Text="ChartWizz" FontFamily="Verdana" FontSize="10" Margin="0,3,0,0" HorizontalAlignment="Center" VerticalAlignment="Center" />
                        <ToggleButton Style="{StaticResource up_down}" Checked="ToggleButton_Checked" />
                        <Image Source="Pictures/logo_250.png" Margin="5"  Grid.Row="1" HorizontalAlignment="Center" VerticalAlignment="Center" />
                        <StackPanel Width="210" Grid.Row="2" Orientation="Horizontal" HorizontalAlignment="Center" >
                            <TextBlock Text="Change User or"  Margin="0,0,3,0" FontFamily="Verdana" FontSize="11" />
                            <Button Style="{StaticResource LinkButton}" Click="CreateNewAccLink_Click" Margin="2, 0, 0, 0">
                                <TextBlock Text="Create new account" FontFamily="Verdana" FontSize="11" Foreground="Black"   TextDecorations="Underline"/>
                            </Button>
                        </StackPanel>
                        <StackPanel Grid.Row="3" Orientation="Vertical" HorizontalAlignment="Center" >
                            <TextBlock  Text="Username" FontFamily="Verdana" FontSize="10" Margin="0,0,0,3" HorizontalAlignment="Left" VerticalAlignment="Center" />
                            <TextBox Width="210" Height="20" HorizontalAlignment="Left" />
                        </StackPanel>
                        <StackPanel Grid.Row="4" Orientation="Vertical" HorizontalAlignment="Center" >
                            <TextBlock  Text="Password" FontFamily="Verdana" FontSize="10" Margin="0,4,0,3" HorizontalAlignment="Left" VerticalAlignment="Center" />
                            <PasswordBox Width="210" Height="20" HorizontalAlignment="Left"  />
                        </StackPanel>
                        <Grid Grid.Row="5" HorizontalAlignment="Left" >
                            <Button Style="{StaticResource LinkButton}" Click="ForgotPassLink_Click" Margin="2, 0, 0, 0" HorizontalAlignment="Left">
                                <TextBlock  Text="Forgot your password?"  Width="Auto" Foreground="Black" TextDecorations="Underline" FontFamily="Verdana" FontSize="10" Margin="27,5,0,3" HorizontalAlignment="Left" VerticalAlignment="Center" />
                            </Button>
                        </Grid>
                        <StackPanel Grid.Row="7" Width="210" Margin="0,5,0,0" Orientation="Horizontal" HorizontalAlignment="Center" >
                            <CheckBox  Content="Remember me" FontFamily="Verdana" FontSize="10" Margin="0,4,0,3" HorizontalAlignment="Left" VerticalAlignment="Center" />
                            <Button Width="60" Content="Sign in" Height="23" Margin="55,0,0,0" VerticalAlignment="Center" Click="SiginBtn_Click" />
                        </StackPanel>
                    </Grid>
                </Border>
            </Grid>
        </view:Content.ChildContent>
    </view:Content>

当我试图给这里的控件命名,以便在代码中访问它们时,我得到了以下错误:

无法在元素"TextBox"上设置Name属性值"txtBox_username"TextBox"位于元素"Content"的作用域下,当在另一个作用域中定义时,该元素已经注册了名称。

我不知道是否有可能通过内容范围以其他方式访问这些成员,但如果有人能启发我,我将不胜感激。无论哪种方式,我都非常想要一个相关MSDN页面(或其他资源)的链接,因为我似乎不知道该搜索什么来了解更多关于类型标记的信息。

感谢

<;视图:内容>;XAML中的标记

这种行为是由UserControls的实现方式引起的,有关解决方法,请参阅此问题。