Having Two Buttons does not render but one button does
I have found that if I have one button (button1) below, the XAML will render correctly but I have two buttons (button1 and button2), nothing will render. The ButtonLoaded method never gets called. What is causing this behavior?
Michael S. Scherotter
Mindjet Labs
JavaScript:
var
margin = 3;//Adjust the button size
function
ButtonLoaded(sender, eventArgs){
var text = sender.findName(sender.Name +"_Text");text[
"Canvas.Top"] = margin;text[
"Canvas.Left"] = margin;var rectangle = sender.findName(sender.Name +"_Rectangle");rectangle.Width = text.ActualWidth + margin * 2;
rectangle.Height = text.ActualHeight + margin * 2;
sender.Width = rectangle.Width;
sender.Height = rectangle.Height;
}
<?xml version="1.0" encoding="utf-8"?>
-<Canvas xmlns="http://schemas.microsoft.com/client/2007" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> -<Canvas x:Name="button1" Canvas.Top="0" Loaded="javascript:ButtonLoaded"> -<Rectangle x:Name="button1_Rectangle" Stroke="#FF8E8E8E" StrokeThickness="2" RadiusX="2" RadiusY="2"> -<LinearGradientBrush x:Name="button1_RectangleBrush" StartPoint="0.5,2.109" EndPoint="0.5,-1.109"> <GradientStopx:Name="gradientStop1" Color="#FFFF9E00" Offset="1" />
<GradientStopx:Name="gradientStop2" Color="#FFEAEAEA" Offset="0.218" />
</LinearGradientBrush>
</Rectangle.Fill>
</Rectangle>
<TextBlockx:Name="button1_Text" Text="button 1" />
</Canvas>
-<Canvas x:Name="button2" Canvas.Top="20" Loaded="javascript:ButtonLoaded"> -<Rectangle x:Name="button2_Rectangle" Stroke="#FF8E8E8E" StrokeThickness="2" RadiusX="2" RadiusY="2"> -<LinearGradientBrush x:Name="button2_RectangleBrush" StartPoint="0.5,2.109" EndPoint="0.5,-1.109"> <GradientStopx:Name="gradientStop1" Color="#FFFF9E00" Offset="1" />
<GradientStopx:Name="gradientStop2" Color="#FFEAEAEA" Offset="0.218" />
</LinearGradientBrush>
</Rectangle.Fill>
</Rectangle>
<TextBlockx:Name="button2_Text" Text="button 2" />
</Canvas>
</Canvas>
Try changing the names of the gradient stops in the second button:
<Canvas x:Name="button2" Canvas.Top="20" Loaded=ButtonLoaded">
<Rectangle x:Name="button2_Rectangle" Stroke="#FF8E8E8E" StrokeThickness="2" RadiusX="2" RadiusY="2">
<Rectangle.Fill>
<LinearGradientBrush x:Name="button2_RectangleBrush" StartPoint="0.5,2.109" EndPoint="0.5,-1.109">
<GradientStop x:Name="gradientStop3" Color="#FFFF9E00" Offset="1" />
<GradientStop x:Name="gradientStop4" Color="#FFEAEAEA" Offset="0.218" />
</LinearGradientBrush>
</Rectangle.Fill>
</Rectangle>
<TextBlock x:Name="button2_Text" Text="button 2" />
</Canvas>
You can only use the names once...