我正在使用静态资源设计WPF表单。我正在使用以下代码来设计登录表单。
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="WpfApplication1.Login"
x:Name="Window"
Title="IntelCall | Login"
Width="640" Height="450" ResizeMode="NoResize" SizeToContent="WidthAndHeight" WindowStartupLocation="CenterScreen" WindowStyle="None">
<Window.Background>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="Black" Offset="0"/>
<GradientStop Color="White" Offset="1"/>
</LinearGradientBrush>
</Window.Background>
<Window.Resources>
<Style x:Key="DefaultButton" TargetType="Button">
<Setter Property="OverridesDefaultStyle" Value="True"/>
<Setter Property="FontSize" Value="16px"/>
<Setter Property="Foreground" Value="White"/>
<Setter Property="Width" Value="125"/>
<Setter Property="Background" >
<Setter.Value>
<LinearGradientBrush EndPoint="0.5,4.201" StartPoint="0.5,-3.792">
<GradientStop Color="#FF001D4F"/>
<GradientStop Color="White" Offset="1"/>
<GradientStop Color="#FF001D4F" Offset="0.515"/>
</LinearGradientBrush>
</Setter.Value>
</Setter>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Border Name="border"
BorderThickness="2"
BorderBrush="White"
CornerRadius="5"
Background="{TemplateBinding Background}">
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Window.Resources>
<Grid x:Name="LayoutRoot">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="640"/>
</Grid.ColumnDefinitions>
<Grid.Background>
<LinearGradientBrush EndPoint="0.495,1.258" StartPoint="0.496,-0.049">
<GradientStop Color="#FF001D4F" Offset="0.249"/>
<GradientStop Color="#FF5888DA" Offset="1"/>
<GradientStop Color="#FF073A93" Offset="0.838"/>
</LinearGradientBrush>
</Grid.Background>
<Rectangle HorizontalAlignment="Stretch" Height="44.734" Margin="0,405.766,0,-0.5" Stroke="Black" StrokeThickness="0" VerticalAlignment="Top" Grid.ColumnSpan="3">
<Rectangle.Fill>
<LinearGradientBrush EndPoint="0.901,0.84" StartPoint="-0.164,0.84">
<GradientStop Color="#FF001D4F" Offset="0.22"/>
<GradientStop Color="#FF001D4F" Offset="0.878"/>
</LinearGradientBrush>
</Rectangle.Fill>
</Rectangle>
<TextBox HorizontalAlignment="Left" Height="27.074" Margin="356.049,164.54,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="264.152" Background="Transparent" BorderBrush="White" BorderThickness="2" Foreground="White" Padding="3"/>
<TextBox HorizontalAlignment="Left" Height="27.074" Margin="356.049,224.54,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="264.152" Background="Transparent" BorderBrush="White" BorderThickness="2" Foreground="White" Padding="3"/>
<Label x:Name="label_Copy" Content="Login ID" HorizontalAlignment="Left" Margin="200.978,158.154,0,0" VerticalAlignment="Top" FontSize="18.667" Foreground="White" FontFamily="Microsoft MHei" RenderTransformOrigin="0.694,0.477" Height="33.46" Width="93.723">
<Label.RenderTransform>
<TransformGroup>
<ScaleTransform/>
<SkewTransform/>
<RotateTransform/>
<TranslateTransform/>
</TransformGroup>
</Label.RenderTransform>
</Label>
<Label x:Name="label_Copy1" Content="Login Password" HorizontalAlignment="Left" Margin="200.978,218.154,0,0" VerticalAlignment="Top" FontSize="18.667" Foreground="White" FontFamily="Microsoft MHei" RenderTransformOrigin="0.694,0.477" Height="33.46" Width="146.223">
<Label.RenderTransform>
<TransformGroup>
<ScaleTransform/>
<SkewTransform/>
<RotateTransform/>
<TranslateTransform/>
</TransformGroup>
</Label.RenderTransform>
</Label>
<Button Style="{StaticResource DefaultButton}" x:Name="BtnLogin" Content="Login" HorizontalAlignment="Left" Margin="356.049,279,0,0" VerticalAlignment="Top" Width="125" Height="30.46">
</Button>
<Button Style="{StaticResource DefaultButton}" x:Name="BtnReset" HorizontalAlignment="Left" Margin="495.201,279,0,0" VerticalAlignment="Top" Height="30.46" FontFamily="/WpfApplication1;component/Fonts/#Segoe UI">
Reset
</Button>
<Image Margin="37.511,161.585,431.034,116.96" Source="Image/Phone.png" RenderTransformOrigin="0.5,0.5">
<Image.RenderTransform>
<TransformGroup>
<ScaleTransform/>
<SkewTransform/>
<RotateTransform Angle="-82.577"/>
<TranslateTransform/>
</TransformGroup>
</Image.RenderTransform>
</Image>
<Label Content="Intel" HorizontalAlignment="Left" Margin="210.274,10,0,0" VerticalAlignment="Top" FontSize="48" Foreground="White" FontFamily="Microsoft MHei"/>
<Label Content="Call" HorizontalAlignment="Left" Margin="309.171,-4.444,0,0" VerticalAlignment="Top" FontSize="48" Foreground="White" FontFamily="Kozuka Gothic Pro B" FontWeight="Bold"/>
<Label Content="v1.0" HorizontalAlignment="Left" Margin="401.201,27.266,0,0" VerticalAlignment="Top" FontSize="32" Foreground="White" FontFamily="Microsoft MHei"/>
</Grid>
我的问题是,按钮内容&#34;重置&#34;和&#34;登录&#34;不可见。 如果我删除静态资源并在按钮标记中提供所有属性,则按钮内容可以正常工作
感谢您的帮助,这是输出的URL http://prntscr.com/70lccv
答案 0 :(得分:1)
在您的ControlTemplate
中,您应该ContentPresenter
来显示Button
的内容。
定义ControlTemplate时,还应定义如何显示按钮的内容。您可以使用ContentPresenter
来显示内容。您还可以使用TextBox
或TextBlock
或Label
等来显示按钮的内容。
见下面的代码。
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Border Name="border"
BorderThickness="2"
BorderBrush="White"
CornerRadius="5"
Background="{TemplateBinding Background}">
<ContentPresenter Content="{TemplateBinding Content}" HorizontalAlignment="Center" VerticalAlignment="Center"/>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>