[TemplatePart(Name =
"Part_Root", Type =
typeof(Panel))]
[
TemplatePart(Name =
"Part_Caption", Type =
typeof(TextBlock))]
[TemplatePart(Name =
"Part_ForegroundRect", Type =
typeof(Rectangle))]
[
TemplatePart(Name =
"Part_BackgroundRect", Type =
typeof(Rectangle))]
[TemplatePart(Name =
"Part_HighlightRect", Type =
typeof(Rectangle))]
[
TemplatePart(Name =
"Part_MouseEnter", Type =
typeof(Storyboard))]
[TemplatePart(Name =
"Part_MouseLeave", Type =
typeof(Storyboard))]
[
TemplatePart(Name =
"Part_MouseDown", Type =
typeof(Storyboard))]
[TemplatePart(Name =
"Part_MouseUp", Type =
typeof(Storyboard))]
public
abstract
partial
class
ButtonBase :
Control
{
public
event
EventHandler Click;protected
void OnClick()
{
if (Click !=
null)
{
Click(this,
new
EventArgs());
}
}
public
string Caption
{
get {
return
this.Part_Caption.Text; }set {
this.Part_Caption.Text =
value; }
I dont know why you have the Button there, but it seems that there is also a Button Control inside Windows.Controls. Do you want to use that? Or you want to use your own one? If so, you can add the existing Button from Windows.Controls first, and edit a
template inside Blend. In such case, all the event and properties are remained to be inherited in your new developed Button.
Can I answer you question? It seems I made things more messy
diesen
Member
7 Points
14 Posts
Unknown attribute Name on element
Oct 25, 2008 11:26 PM | LINK
Hi
I did download an example ( http://silverlight.net//samples/sl2/imagesnipperv2/source/Source_ImageSnipper_CS.zip) and tried to change the namespace to another name. After doing the program stop working
Now I just remove a lot of the code and files and left with some simples project .
I'm still getting " Unknown attribute Name on element " error
The strange thing when I compile i don't see any compilation errors, but i see the error at run time or just when I open the page.xaml file
<ctl:Button x:Name="testName" ></ctl:Button> is the line that does make the error
I have the following files and content
Page.xaml
<
UserControl x:Class="TestMenue.Page" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:ctl="clr-namespace:TestMenue" Width="400" Height="300"> <Canvas x:Name='root' Width='800' Height='600' Loaded='root_Loaded'> <ctl:Button x:Name="testName" ></ctl:Button> </Canvas></
UserControl><!--
/////////////////////////////////////////////////////////////////////////
//
// ButtonBase.xaml
//
//
// © 2008 Microsoft Corporation. All Rights Reserved.
//
// This file is licensed as part of the Silverlight 2 SDK, for details look here: http://go.microsoft.com/fwlink/?LinkID=111970&clcid=0x409
//
///////////////////////////////////////////////////////////////////////////////
-->
<
ControlTemplate xmlns="http://schemas.microsoft.com/client/2007" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" > <Grid x:Name="Part_Root" MouseEnter="btnClearMouseEnter" MouseLeave="btnClearMouseLeave" MouseLeftButtonDown="btnClearMouseDown" MouseLeftButtonUp="btnClearMouseUp"> <Grid.Resources> <Storyboard x:Name="Part_MouseEnter"/> <Storyboard x:Name="Part_MouseDown"/> <Storyboard x:Name="Part_MouseUp"/> <Storyboard x:Name="Part_MouseLeave"/> </Grid.Resources> <Rectangle x:Name="Part_BackgroundRect"/> <TextBlock x:Name="Part_Caption"/> <Rectangle x:Name="Part_ForegroundRect"/> <Rectangle x:Name="Part_HighlightRect"/> </Grid></
ControlTemplate>/////////////////////////////////////////////////////////////
//
// ButtonBase.xaml.cs
//
// © 2008 Microsoft Corporation. All Rights Reserved.
//
// This file is licensed with terms as outlined here:
// http://go.microsoft.com/fwlink/?LinkID=111970&clcid=0x409
//
/////////////////////////////////////////////////////////////
using
System;using
System.Windows;using
System.Windows.Controls;using
System.Windows.Documents;using
System.Windows.Ink;using
System.Windows.Input;using
System.Windows.Markup;using
System.Windows.Media;using
System.Windows.Media.Animation;using
System.Windows.Shapes; namespace TestMenue{
[TemplatePart(Name = "Part_Root", Type = typeof(Panel))][
TemplatePart(Name = "Part_Caption", Type = typeof(TextBlock))] [TemplatePart(Name = "Part_ForegroundRect", Type = typeof(Rectangle))][
TemplatePart(Name = "Part_BackgroundRect", Type = typeof(Rectangle))] [TemplatePart(Name = "Part_HighlightRect", Type = typeof(Rectangle))][
TemplatePart(Name = "Part_MouseEnter", Type = typeof(Storyboard))] [TemplatePart(Name = "Part_MouseLeave", Type = typeof(Storyboard))][
TemplatePart(Name = "Part_MouseDown", Type = typeof(Storyboard))] [TemplatePart(Name = "Part_MouseUp", Type = typeof(Storyboard))] public abstract partial class ButtonBase : Control{
public event EventHandler Click;protected void OnClick(){
if (Click != null){
Click(this, new EventArgs());}
}
public string Caption{
get { return this.Part_Caption.Text; }set { this.Part_Caption.Text = value; }}
protected virtual void Part_Root_MouseEnter(object sender, MouseEventArgs e){
Part_MouseEnter.Begin();
}
protected virtual void Part_Root_MouseLeave(object sender, MouseEventArgs e){
Part_MouseLeave.Begin();
}
protected virtual void Part_Root_MouseLeftButtonDown(object sender, MouseButtonEventArgs e){
Part_MouseDown.Begin();
}
protected virtual void Part_Root_MouseLeftButtonUp(object sender, MouseButtonEventArgs e){
Part_MouseUp.Begin();
OnClick();
}
protected Storyboard Part_MouseEnter, Part_MouseDown, Part_MouseLeave, Part_MouseUp; protected Rectangle Part_ForegroundRect, Part_BackgroundRect, Part_HighlightRect; protected Panel Part_Root;protected TextBlock Part_Caption;}
}
<!--
/////////////////////////////////////////////////////////////////////////
//
// Button.xaml
//
//
// © 2008 Microsoft Corporation. All Rights Reserved.
//
// This file is licensed as part of the Silverlight 2 SDK, for details look here: http://go.microsoft.com/fwlink/?LinkID=111970&clcid=0x409
//
///////////////////////////////////////////////////////////////////////////////
-->
<
ControlTemplate xmlns="http://schemas.microsoft.com/client/2007" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" > <Grid x:Name="Part_Root" MouseEnter="btnClearMouseEnter" MouseLeave="btnClearMouseLeave" MouseLeftButtonDown="btnClearMouseDown" MouseLeftButtonUp="btnClearMouseUp"> <Grid.Resources> <Storyboard x:Name="Part_MouseEnter"> <ColorAnimation Duration="00:00:00.25" To="#3DFFFFFF" Storyboard.TargetName="Part_HighlightRect" Storyboard.TargetProperty="(Shape.Fill).(SolidColorBrush.Color)" /> </Storyboard> <Storyboard x:Name="Part_MouseDown"> <ColorAnimation Duration="00:00:00.2" To="#22000000" Storyboard.TargetName="Part_HighlightRect" Storyboard.TargetProperty="(Shape.Fill).(SolidColorBrush.Color)" /> </Storyboard> <Storyboard x:Name="Part_MouseUp"> <ColorAnimation Duration="00:00:00.2" To="#3DFFFFFF" Storyboard.TargetName="Part_HighlightRect" Storyboard.TargetProperty="(Shape.Fill).(SolidColorBrush.Color)" /> </Storyboard> <Storyboard x:Name="Part_MouseLeave"> <ColorAnimation Duration="00:00:00.25" To="#00FFFFFF" Storyboard.TargetName="Part_HighlightRect" Storyboard.TargetProperty="(Shape.Fill).(SolidColorBrush.Color)" /> </Storyboard> </Grid.Resources> <Rectangle x:Name="Part_BackgroundRect" StrokeThickness="4" RadiusX="16" RadiusY="36" Stroke="#46000000"> <Rectangle.Fill> <LinearGradientBrush EndPoint="0.5,-0.4" StartPoint="0.5,1.4"> <GradientStop Color="Gray" Offset="0.242"/> <GradientStop Color="DarkBlue" Offset="0.333"/> </LinearGradientBrush> </Rectangle.Fill> </Rectangle> <TextBlock x:Name="Part_Caption" VerticalAlignment="Center" HorizontalAlignment="Center" Foreground="Gold" Text="Button"> <TextBlock.RenderTransform> <TranslateTransform X="0" Y="-2"/> </TextBlock.RenderTransform> </TextBlock> <Rectangle x:Name="Part_ForegroundRect" VerticalAlignment="Top" StrokeThickness="4" RadiusX="16" RadiusY="36" Width="124" Height="32"> <Rectangle.Fill> <LinearGradientBrush EndPoint="0.5,-0.409" StartPoint="0.5,1.409"> <GradientStop Color="#00FFFFFF" Offset="0.13"/> <GradientStop Color="#FFFFFFFF" Offset="1"/> </LinearGradientBrush> </Rectangle.Fill> </Rectangle> <Rectangle VerticalAlignment="Top" RadiusX="16" RadiusY="36" Fill="#00FFFFFF" x:Name="Part_HighlightRect"/> </Grid></
ControlTemplate>/////////////////////////////////////////////////////////////
//
// Button.xaml.cs
//
// © 2008 Microsoft Corporation. All Rights Reserved.
//
// This file is licensed with terms as outlined here:
// http://go.microsoft.com/fwlink/?LinkID=111970&clcid=0x409
//
/////////////////////////////////////////////////////////////
using
System;using
System.Windows;using
System.Windows.Controls;using
System.Windows.Documents;using
System.Windows.Ink;using
System.Windows.Input;using
System.Windows.Markup;using
System.Windows.Media;using
System.Windows.Media.Animation;using
System.Windows.Shapes; namespace ImageSnipperV2{
public partial class Button : ButtonBase{
public Button(){
string xaml = ResourceHelper.GetTemplate(this.GetType()); ControlTemplate template = (ControlTemplate)XamlReader.Load(xaml); this.Template = template;this.ApplyTemplate();}
public override void OnApplyTemplate(){
Part_Root = (
Panel)GetTemplateChild("Part_Root"); Part_Caption = (TextBlock)GetTemplateChild("Part_Caption");Part_ForegroundRect = (
Rectangle)GetTemplateChild("Part_ForegroundRect"); Part_BackgroundRect = (Rectangle)GetTemplateChild("Part_BackgroundRect");Part_HighlightRect = (
Rectangle)GetTemplateChild("Part_HighlightRect"); Part_MouseEnter = (Storyboard)GetTemplateChild("Part_MouseEnter");Part_MouseLeave = (
Storyboard)GetTemplateChild("Part_MouseLeave"); Part_MouseDown = (Storyboard)GetTemplateChild("Part_MouseDown");Part_MouseUp = (
Storyboard)GetTemplateChild("Part_MouseUp"); Part_Root.SizeChanged += new SizeChangedEventHandler(Part_Root_SizeChanged);Part_Root.MouseEnter +=
new MouseEventHandler(Part_Root_MouseEnter); Part_Root.MouseLeave += new MouseEventHandler(Part_Root_MouseLeave);Part_Root.MouseLeftButtonDown +=
new MouseButtonEventHandler(Part_Root_MouseLeftButtonDown); Part_Root.MouseLeftButtonUp += new MouseButtonEventHandler(Part_Root_MouseLeftButtonUp);}
void Part_Root_SizeChanged(object sender, SizeChangedEventArgs e){
Part_ForegroundRect.Width = Part_Root.ActualWidth - 16d;
Part_ForegroundRect.Height = Part_Root.ActualHeight - 12d;
Part_HighlightRect.Width = Part_Root.ActualWidth - 10d;
Part_HighlightRect.Height = Part_Root.ActualHeight - 8d;
if (Part_Root.ActualWidth > Part_Root.ActualHeight){
Part_BackgroundRect.RadiusX = Part_ForegroundRect.RadiusX = Part_HighlightRect.RadiusX = Part_Root.ActualHeight / 2d;
Part_BackgroundRect.RadiusY = Part_ForegroundRect.RadiusY = Part_HighlightRect.RadiusY = Part_Root.ActualWidth / 4d;
}
else{
Part_BackgroundRect.RadiusX = Part_ForegroundRect.RadiusX = Part_HighlightRect.RadiusX = Part_Root.ActualHeight / 4d;
Part_BackgroundRect.RadiusY = Part_ForegroundRect.RadiusY = Part_HighlightRect.RadiusY = Part_Root.ActualWidth / 2d;
}
}
}
}
SteveWong
Contributor
6719 Points
1346 Posts
Re: Unknown attribute Name on element
Oct 26, 2008 06:39 PM | LINK
I dont know why you have the Button there, but it seems that there is also a Button Control inside Windows.Controls. Do you want to use that? Or you want to use your own one? If so, you can add the existing Button from Windows.Controls first, and edit a template inside Blend. In such case, all the event and properties are remained to be inherited in your new developed Button.
Can I answer you question? It seems I made things more messy
SteveWong (HongKong)
Please mark post as answer if they help you
babyboyface
Member
5 Points
6 Posts
Re: Unknown attribute Name on element
Feb 26, 2009 10:48 AM | LINK
pls refer to http://silverlight.net/forums/p/30696/179676.aspx .