1
votes

I'm trying to create a settings flyout (Windows 8 App in C#) and since the background of the flyout is white I like to kinda' invert the page controls to make them visible form default. I have managed to change border color of the TextBoxes. But when I "invert" all the button stuff and click the button the app breaks on this line.

if (global::System.Diagnostics.Debugger.IsAttached) global::System.Diagnostics.Debugger.Break();

This is the XAML for the usercontrol:

<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>

In the CS file I have add a handler but it doesn't respond at all.

public sealed partial class Settings : UserControl
{
    public Settings()
    {
        this.InitializeComponent();
        login.Click+=login_Click;
    }

    private void login_Click(object sender, RoutedEventArgs e)
    {

    }
}

If I remove the button styling everything acts as normal

What to do/don't do?

1

1 Answers

1
votes

You miss an "e" in Foreground

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