C# 按钮单击与自定义控件模板绑定?

C# 按钮单击与自定义控件模板绑定?,c#,winrt-xaml,C#,Winrt Xaml,我正在尝试创建一个设置弹出按钮(C#中的Windows 8应用程序),由于弹出按钮的背景是白色的,我喜欢将页面控件倒置,使其在默认情况下可见。我已经设法改变了文本框的边框颜色。但当我“反转”所有按钮并点击按钮时,应用程序在这一行中断 if (global::System.Diagnostics.Debugger.IsAttached) global::System.Diagnostics.Debugger.Break(); 这是usercontrol的XAML: <UserControl

我正在尝试创建一个设置弹出按钮(C#中的Windows 8应用程序),由于弹出按钮的背景是白色的,我喜欢将页面控件倒置,使其在默认情况下可见。我已经设法改变了文本框的边框颜色。但当我“反转”所有按钮并点击按钮时,应用程序在这一行中断

if (global::System.Diagnostics.Debugger.IsAttached) global::System.Diagnostics.Debugger.Break();
这是usercontrol的XAML:

<UserControl
x:Class="tapp.Settings"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:tapp"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">

<UserControl.Resources>
    <Style x:Key="tb" TargetType="TextBox">
        <Setter Property="BorderBrush" Value="Black"/>
        <Setter Property="Width" Value="200"/>
    </Style>
    <Style x:Key="pb" TargetType="PasswordBox">
        <Setter Property="BorderBrush" Value="Black"/>
        <Setter Property="Width" Value="200"/>
    </Style>
    <Style x:Key="btn" TargetType="Button">
        <Setter Property="BorderBrush" Value="Black"/>
        <Setter Property="Foreground" Value="Black"/>
        <Setter Property="Background" Value="White"/>
        <Setter Property="ClickMode" Value="Press"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="Button">
                    <Grid Height="{TemplateBinding Height}" Width="{TemplateBinding Width}">
                        <Rectangle x:Name="outRect"
                                   HorizontalAlignment="Stretch"
                                   VerticalAlignment="Stretch"
                                   Fill="Black">
                        </Rectangle>
                        <Rectangle x:Name="innerRect"
                                   HorizontalAlignment="Stretch"
                                   VerticalAlignment="Stretch"
                                   Margin="2"
                                   Opacity="100"
                                   Fill="White">
                        </Rectangle>
                        <ContentPresenter x:Name="cpresent" Content="{TemplateBinding Content}" HorizontalAlignment="Center" VerticalAlignment="Center"/>
                        <VisualStateManager.VisualStateGroups>
                            <VisualStateGroup x:Name="CommonStates">
                                <VisualState x:Name="Normal"/>
                                <VisualState x:Name="PointerOver">
                                    <Storyboard Duration="0">
                                        <ColorAnimation To="LightGray" Duration="0"                    Storyboard.TargetProperty="(Rectangle.Fill).(SolidColorBrush.Color)" Storyboard.TargetName="innerRect" />
                                    </Storyboard>
                                </VisualState>
                                <VisualState x:Name="Pressed">
                                    <Storyboard>
                                        <ColorAnimation To="Black" Duration="0"                    Storyboard.TargetProperty="(Rectangle.Fill).(SolidColorBrush.Color)" Storyboard.TargetName="innerRect" />
                                        <ColorAnimation To="White" Duration="0" Storyboard.TargetProperty="(ContentPresenter.Forground).(SolidColorBrush.Color)" Storyboard.TargetName="cpresent"/>
                                    </Storyboard>
                                </VisualState>
                            </VisualStateGroup>
                        </VisualStateManager.VisualStateGroups>
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</UserControl.Resources>

<Grid>
    <TextBlock HorizontalAlignment="Left" Margin="10,10,0,0" TextWrapping="Wrap" Text="Username" VerticalAlignment="Top"/>
    <TextBox x:Name="username" HorizontalAlignment="Left" Margin="10,28,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Height="30" Style="{StaticResource ResourceKey=tb}"/>
    <TextBlock HorizontalAlignment="Left" Margin="10,65,0,0" TextWrapping="Wrap" Text="Password" VerticalAlignment="Top"/>
    <PasswordBox x:Name="password" HorizontalAlignment="Left" Margin="10,83,0,0" VerticalAlignment="Top" Style="{StaticResource ResourceKey=pb}"/>
    <Button x:Name="login" Content="Login" HorizontalAlignment="Left" Margin="10,120,0,0" VerticalAlignment="Top" Width="200" Height="32" Style="{StaticResource btn}"/>

</Grid>
如果我删除按钮样式,一切正常

做什么/不做什么?

你错过了前景中的一个“e”

<ColorAnimation To="White" Duration="0" Storyboard.TargetProperty="(ContentPresenter.Foreground).(SolidColorBrush.Color)" Storyboard.TargetName="cpresent"/>

前景中缺少一个“e”

<ColorAnimation To="White" Duration="0" Storyboard.TargetProperty="(ContentPresenter.Foreground).(SolidColorBrush.Color)" Storyboard.TargetName="cpresent"/>