这是一个xaml文件App.xaml。
<Application x:Class="Fifteen.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:Fifteen"
StartupUri="MainWindow.xaml">
<Application.Resources>
<Style TargetType="{x:Type local:Cell}">
<Setter Property="Canvas.Top" Value="{Binding Top, RelativeSource={RelativeSource Self}}" />
<Setter Property="Canvas.Left" Value="{Binding Left, RelativeSource={RelativeSource Self}}" />
<Setter Property="Background">
<Setter.Value>
<LinearGradientBrush StartPoint="0.5,0" EndPoint="0.5,1">
<GradientStop Offset="0" Color="#F7F7F7" />
<GradientStop Offset="1" Color="#E3E3E3" />
</LinearGradientBrush>
</Setter.Value>
</Setter>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type local:Cell}">
<Border Name="border"
Width="75"
Height="75"
Background="{TemplateBinding Background}"
BorderBrush="Silver"
BorderThickness="1"
CornerRadius="2">
<TextBlock Name="text"
HorizontalAlignment="Center"
VerticalAlignment="Center"
FontSize="22"
Text="{TemplateBinding Text}" />
</Border>
<ControlTemplate.Triggers>
<DataTrigger Binding="{Binding IsMouseOver, RelativeSource={RelativeSource Self}}" Value="True">
<Setter TargetName="text" Property="Foreground" Value="Red" />
<Setter TargetName="border" Property="Effect">
<Setter.Value>
<DropShadowEffect ShadowDepth="0" />
</Setter.Value>
</Setter>
</DataTrigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
<Style.Triggers>
<DataTrigger Binding="{Binding IsMouseOver, RelativeSource={RelativeSource Self}}" Value="True">
<Setter Property="Background" Value="Beige" />
<Setter Property="Cursor" Value="Hand" />
</DataTrigger>
</Style.Triggers>
</Style>
</Application.Resources>
在带有标签的行上我有错误
名称“Cell”在名称空间“clr-namespace:Fifteen”中不存在。
如果此类位于此名称空间中,我无法解释为何将其生成为错误。这里:
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media.Animation;
namespace Fifteen
{
public class Cell : Control
{
static Cell()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(Cell), new
FrameworkPropertyMetadata(typeof(Cell)));
}
}
}