0
我正在修改默認的「ChildWindow」樣式,我想指定與默認情況下存在的「X」不同的圖像。我已經嘗試過各種東西,比如鉤住OnApplyTemplate和OnOpened,在那裏我可以得到編程訪問按鈕,像這樣:更改ChildWindow CloseButton圖像Silverlight 3
Button closeButton = this.GetTemplateChild("CloseButton") as Button;
然而closeButton.Content總是空。我已經嘗試將其設置爲我的圖像,它確實設置,但用戶界面仍然顯示默認的'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增加了圖像的按鈕,它仍然沒有露面。