用c#wpf模板建立一个圆形的button
xaml文件是:<Windowx:Class="s1.MainWindow"xmlns="http://schemas.microsoft.com/winfx/2006/...
xaml文件是:
<Window x:Class="s1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Grid>
<Grid.Resources>
<ControlTemplate x:Key="ButtonTemplate" TargetType="{x:Type Button}">
<Grid>
<Ellipse Name="OuterRing" Width="75" Height="75" Fill="DarkGreen"/>
<Ellipse Name="InnerRing" Width="60" Height="60" Fill="MintCream"/>
<ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center"/>
</Grid>
</ControlTemplate>
</Grid.Resources>
<Button Name="button1" Foreground="Black" FontSize="20" Template="StaticResource ButtonTemplate">Button</Button>
</Grid>
</Window>
cs文件是:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace s1
{
/// <summary>
/// MainWindow.xaml 的交互逻辑
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
}
}
但调试会出错
在 System.Windows.Markup.XamlParseException 中第一次偶然出现的“PresentationFramework.dll”类型的异常
其他信息: “设置属性“System.Windows.Controls.Control.Template”时引发了异常。”,行号为“15”,行位置为“51”。
跪求大侠指点
分只有这么多了,见谅!! 展开
<Window x:Class="s1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Grid>
<Grid.Resources>
<ControlTemplate x:Key="ButtonTemplate" TargetType="{x:Type Button}">
<Grid>
<Ellipse Name="OuterRing" Width="75" Height="75" Fill="DarkGreen"/>
<Ellipse Name="InnerRing" Width="60" Height="60" Fill="MintCream"/>
<ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center"/>
</Grid>
</ControlTemplate>
</Grid.Resources>
<Button Name="button1" Foreground="Black" FontSize="20" Template="StaticResource ButtonTemplate">Button</Button>
</Grid>
</Window>
cs文件是:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace s1
{
/// <summary>
/// MainWindow.xaml 的交互逻辑
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
}
}
但调试会出错
在 System.Windows.Markup.XamlParseException 中第一次偶然出现的“PresentationFramework.dll”类型的异常
其他信息: “设置属性“System.Windows.Controls.Control.Template”时引发了异常。”,行号为“15”,行位置为“51”。
跪求大侠指点
分只有这么多了,见谅!! 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询