UWP用户控件无法实例化MyUserControl

时间:2018-10-25 16:49:30

标签: c# uwp user-controls

我的Uwp应用程序可以构建并正常运行。用户控件在用户控件设计器中可见。最初将控件添加到主页时,该控件在设计器中可见。我运行该应用程序,然后返回到设计的主页面,用户控件消失了,并且xaml说“无法安装类型为用户控件的对象。我不明白为什么该控件在用户控件设计器中可见,但是为什么主页设计师,并且该应用运行良好。

还有其他人遇到这个问题吗?有什么线索可以在用户控件中找到问题? 用户控件的XAML:

<UserControl
x:Class="UI_Test_1.Controls.BookingTimeControl"
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:local="using:UI_Test_1.Views"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:telerik="using:Telerik.UI.Xaml.Controls.Input"
xmlns:uControls="using:UI_Test_1.Controls"
d:DesignHeight="400"
d:DesignWidth="500"
mc:Ignorable="d">

<UserControl.Resources>
    <Style x:Key="ListBoxItemContainerStyle1" TargetType="ListBoxItem">
        <Setter Property="Background" Value="Transparent" />
        <Setter Property="TabNavigation" Value="Local" />
        <Setter Property="Padding" Value="5,5,5,5" />
        <Setter Property="HorizontalContentAlignment" Value="Left" />
        <Setter Property="UseSystemFocusVisuals" Value="{StaticResource UseSystemFocusVisuals}" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="ListBoxItem">
                    <Grid
                        x:Name="LayoutRoot"
                        Background="{TemplateBinding Background}"
                        BorderThickness="{TemplateBinding BorderThickness}">
                        <Grid.Resources>
                            <Style x:Key="BaseContentPresenterStyle" TargetType="ContentPresenter">
                                <Setter Property="FontFamily" Value="XamlAutoFontFamily" />
                                <Setter Property="FontWeight" Value="Bold" />
                                <Setter Property="FontSize" Value="10" />
                                <Setter Property="TextWrapping" Value="Wrap" />
                                <Setter Property="LineStackingStrategy" Value="MaxHeight" />
                                <Setter Property="TextLineBounds" Value="Full" />
                                <Setter Property="OpticalMarginAlignment" Value="TrimSideBearings" />
                            </Style>
                            <Style
                                x:Key="BodyContentPresenterStyle"
                                BasedOn="{StaticResource BaseContentPresenterStyle}"
                                TargetType="ContentPresenter">
                                <Setter Property="FontWeight" Value="Bold" />
                                <Setter Property="FontSize" Value="12" />
                            </Style>
                        </Grid.Resources>
                        <Rectangle
                            x:Name="PressedBackground"
                            Control.IsTemplateFocusTarget="True"
                            Fill="Transparent" />
                        <ContentPresenter
                            x:Name="ContentPresenter"
                            Margin="{TemplateBinding Padding}"
                            HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                            VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                            Content="{TemplateBinding Content}"
                            ContentTemplate="{TemplateBinding ContentTemplate}"
                            ContentTransitions="{TemplateBinding ContentTransitions}"
                            Style="{StaticResource BodyContentPresenterStyle}"
                            TextWrapping="NoWrap" />
                        <VisualStateManager.VisualStateGroups>
                            <VisualStateGroup x:Name="CommonStates">
                                <VisualState x:Name="Normal" />
                                <VisualState x:Name="Disabled">
                                    <Storyboard>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentPresenter" Storyboard.TargetProperty="Foreground">
                                            <DiscreteObjectKeyFrame KeyTime="0" Value="Transparent" />
                                        </ObjectAnimationUsingKeyFrames>
                                    </Storyboard>
                                </VisualState>
                                <VisualState x:Name="PointerOver">
                                    <Storyboard>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="PressedBackground" Storyboard.TargetProperty="Fill">
                                            <DiscreteObjectKeyFrame KeyTime="0" Value="yellow" />
                                        </ObjectAnimationUsingKeyFrames>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentPresenter" Storyboard.TargetProperty="Foreground">
                                            <DiscreteObjectKeyFrame KeyTime="0" Value="Black" />
                                        </ObjectAnimationUsingKeyFrames>
                                    </Storyboard>
                                </VisualState>
                                <VisualState x:Name="Pressed">
                                    <Storyboard>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="PressedBackground" Storyboard.TargetProperty="Fill">
                                            <DiscreteObjectKeyFrame KeyTime="0" Value="Green" />
                                        </ObjectAnimationUsingKeyFrames>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentPresenter" Storyboard.TargetProperty="Foreground">
                                            <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlHighlightAltBaseHighBrush}" />
                                        </ObjectAnimationUsingKeyFrames>
                                    </Storyboard>
                                </VisualState>
                                <VisualState x:Name="Selected">
                                    <Storyboard>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="PressedBackground" Storyboard.TargetProperty="Fill">
                                            <DiscreteObjectKeyFrame KeyTime="0" Value="Transparent" />
                                        </ObjectAnimationUsingKeyFrames>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentPresenter" Storyboard.TargetProperty="Foreground">
                                            <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlHighlightAltBaseHighBrush}" />
                                        </ObjectAnimationUsingKeyFrames>
                                    </Storyboard>
                                </VisualState>
                                <VisualState x:Name="SelectedUnfocused">
                                    <Storyboard>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="PressedBackground" Storyboard.TargetProperty="Fill">
                                            <DiscreteObjectKeyFrame KeyTime="0" Value="Green" />
                                        </ObjectAnimationUsingKeyFrames>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentPresenter" Storyboard.TargetProperty="Foreground">
                                            <DiscreteObjectKeyFrame KeyTime="0" Value="White" />
                                        </ObjectAnimationUsingKeyFrames>
                                    </Storyboard>
                                </VisualState>
                                <VisualState x:Name="SelectedPointerOver">
                                    <Storyboard>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="PressedBackground" Storyboard.TargetProperty="Fill">
                                            <DiscreteObjectKeyFrame KeyTime="0" Value="Green" />
                                        </ObjectAnimationUsingKeyFrames>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentPresenter" Storyboard.TargetProperty="Foreground">
                                            <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlHighlightAltBaseHighBrush}" />
                                        </ObjectAnimationUsingKeyFrames>
                                    </Storyboard>
                                </VisualState>
                                <VisualState x:Name="SelectedPressed">
                                    <Storyboard>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="PressedBackground" Storyboard.TargetProperty="Fill">
                                            <DiscreteObjectKeyFrame KeyTime="0" Value="Transparent" />
                                        </ObjectAnimationUsingKeyFrames>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentPresenter" Storyboard.TargetProperty="Foreground">
                                            <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlHighlightAltBaseHighBrush}" />
                                        </ObjectAnimationUsingKeyFrames>
                                    </Storyboard>
                                </VisualState>
                            </VisualStateGroup>
                        </VisualStateManager.VisualStateGroups>
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>


    <uControls:StringFormatConverter x:Key="dateFormatter" />


</UserControl.Resources>
<Grid>

    <Grid
        Margin="10,10,10,10"
        HorizontalAlignment="Left"
        VerticalAlignment="Top"
        Background="Black">



        <StackPanel
            Grid.Row="0"
            Grid.RowSpan="2"
            Width="445"
            Height="350"
            Margin="5,5,5,5"
            HorizontalAlignment="Left"
            VerticalAlignment="Top"
            Background="Blue"
            Orientation="Horizontal">
            <ListBox
                Name="timeSelectionList"
                Width="135"
                Height="350"
                HorizontalAlignment="Center"
                VerticalAlignment="Top"
                BorderBrush="Black"
                BorderThickness="2"
                GotFocus="Control_GotFocus"
                ItemContainerStyle="{StaticResource ListBoxItemContainerStyle1}"
                ItemsSource="{x:Bind timeSelectors}"
                LostFocus="Control_LostFocus"
                PreviewKeyDown="timeSelectionList_PreviewKeyDown"
                SelectionChanged="TimeSelectionList_SelectionChanged" />
            <StackPanel VerticalAlignment="Top" Orientation="Vertical">
                <DatePicker
                    x:Name="cal"
                    Background="White"
                    Date="{x:Bind viewModel.bookingTime, Mode=TwoWay}"
                    DateChanged="cal_DateChanged"
                    DayFormat="{}{day.integer} {dayofweek.abbreviated}"
                    FontSize="20"
                    GotFocus="Control_GotFocus"
                    LostFocus="Control_LostFocus"
                    Opacity="100"
                    PreviewKeyDown="cal_PreviewKeyDown" />

                <TimePicker
                    x:Name="timePicker"
                    Margin="5"
                    HorizontalAlignment="Center"
                    Background="White"
                    FontSize="20"
                    GotFocus="Control_GotFocus"
                    LostFocus="Control_LostFocus"
                    MinuteIncrement="5"
                    TimeChanged="timePicker_TimeChanged" />


                <TextBox
                    Name="bookingTimeBox"
                    Width="250"
                    Height="auto"
                    Margin="5,0,5,5"
                    Background="Black"
                    FontSize="12"
                    FontWeight="Bold"
                    Foreground="Yellow"
                    Text="{x:Bind viewModel.bookingTime, Mode=OneWay, Converter={StaticResource dateFormatter}}"
                    TextAlignment="Center" />
            </StackPanel>


        </StackPanel>






    </Grid>
</Grid>

0 个答案:

没有答案