Xaml 更改儿童窗口关闭按钮图像Silverlight 3

Xaml 更改儿童窗口关闭按钮图像Silverlight 3,xaml,silverlight-3.0,Xaml,Silverlight 3.0,我正在修改默认的“ChildWindow”样式,我想指定一个与默认的“X”不同的图像。我尝试过各种方法,比如挂接到OnApplyTemplate和OnOpen,在那里我可以通过编程访问按钮,如下所示: Button closeButton = this.GetTemplateChild("CloseButton") as Button; 但是closeButton.Content总是空的。我尝试将其设置为我的图像,但它确实设置好了,但UI仍然显示默认的“X”。我也调用了UpdateLayout

我正在修改默认的“ChildWindow”样式,我想指定一个与默认的“X”不同的图像。我尝试过各种方法,比如挂接到OnApplyTemplate和OnOpen,在那里我可以通过编程访问按钮,如下所示:

Button closeButton = this.GetTemplateChild("CloseButton") as Button;
但是closeButton.Content总是空的。我尝试将其设置为我的图像,但它确实设置好了,但UI仍然显示默认的“X”。我也调用了UpdateLayout()但没有用

有没有一种方法可以通过编程或通过XAML来实现这一点?我复制了默认样式,并进行了受影响的更改,但这是一个让我感到困惑的更改。下面是我一直使用的XAML样式的一个片段:

<!-- Header with Title-->
<Border x:Name="Chrome" Width="Auto" CornerRadius="5,5,0,0" Background="{StaticResource ChildWindowHeaderBackgroundBrush}">
    <Grid Height="Auto" Width="Auto">
        <Grid.ColumnDefinitions>
            <ColumnDefinition/>
            <ColumnDefinition Width="30"/>
        </Grid.ColumnDefinitions>
        <ContentControl Content="{TemplateBinding Title}"
            IsTabStop="False"
            FontWeight="Bold"
            HorizontalAlignment="Stretch"
            VerticalAlignment="Center"
            Margin="6,0,6,0"/>    
        <Button x:Name="CloseButton" Margin="0,5,0,5" Grid.Column="2" IsTabStop="False" HorizontalAlignment="Center" VerticalAlignment="Center" Width="15" Height="14" Style="{StaticResource ButtonStyle}"/>
    </Grid>
</Border>


我已经通过XAML向按钮添加了一个图像,但它仍然没有显示。

所有这些都是通过样式在ControlTemplate中处理的:

<Style x:Key="ButtonStyle" TargetType="Button">
    <Setter Property="Padding" Value="0"/>
    <Setter Property="BorderThickness" Value="0"/>
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="Button">
                <Grid>
                    <VisualStateManager.VisualStateGroups>
                      <VisualStateGroup x:Name="CommonStates">
                        <VisualState x:Name="Disabled"/>
                        <VisualState x:Name="Normal"/>
                        <VisualState x:Name="Pressed"/>
                        <VisualState x:Name="MouseOver">
                          <Storyboard>
                            <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="mouseOverImage">
                              <DiscreteObjectKeyFrame KeyTime="0">
                                <DiscreteObjectKeyFrame.Value>
                                  <Visibility>Visible</Visibility>
                                </DiscreteObjectKeyFrame.Value>
                              </DiscreteObjectKeyFrame>
                            </ObjectAnimationUsingKeyFrames>
                            <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="normalImage">
                              <DiscreteObjectKeyFrame KeyTime="0">
                                <DiscreteObjectKeyFrame.Value>
                                  <Visibility>Collapsed</Visibility>
                                </DiscreteObjectKeyFrame.Value>
                              </DiscreteObjectKeyFrame>
                            </ObjectAnimationUsingKeyFrames>
                          </Storyboard>
                        </VisualState>
                      </VisualStateGroup>
                    </VisualStateManager.VisualStateGroups>
                    <Image x:Name="normalImage" Margin="0" Source="/img/status_unknown.png" Stretch="None" />
                    <Image x:Name="mouseOverImage" Margin="0" Source="/img/up.png" Stretch="None" Visibility="Collapsed" />
                </Grid>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

看得见的
崩溃