1
我試圖創建一個設置彈出窗口(C#中的Windows 8應用程序),並且由於彈出窗口的背景是白色的,我喜歡將'反轉頁面控件以使其可見窗體默認。我設法改變了TextBoxes的邊框顏色。但是,當我「倒置」所有按鈕的東西,並點擊按鈕的應用程序在這一行中斷。按鈕點擊綁定與自定義ControlTemplate?
if (global::System.Diagnostics.Debugger.IsAttached) global::System.Diagnostics.Debugger.Break();
這是用戶控件的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>
在CS文件我已經添加處理程序,但它並沒有任何反應。
public sealed partial class Settings : UserControl
{
public Settings()
{
this.InitializeComponent();
login.Click+=login_Click;
}
private void login_Click(object sender, RoutedEventArgs e)
{
}
}
如果我刪除的按鈕造型的一切作爲正常
怎麼辦/不做?