2009-09-02 22 views
1

下面是適用於所有XAML嚮導的一個:WPF工具包Calendar控制(2009年6月)似乎有一個錯誤。只有當您修改日曆的ControlTemplate時,該錯誤纔會出現,特別是PART_CalendarItemWPF工具包:控制模板中的錯誤?

在該消息的末尾,我已經包括XAML爲(混合3.0)窗口,聲明一個Calendar並給它分配一個ControlTemplate。控件模板是Calendar控件模板的一個未修改的副本,我通過編輯日曆控件和PART_CalendarItem控件的控件模板副本(在Blend中)獲得了該副本。

在XAML的78線(標有評論「例外」下方),則VisualStateManager分配TextColor到鼠標懸停在控制的Month報頭。但是,在控件模板中,文本顏色分配給保存Month按鈕的Grid,而不是月份按鈕本身。當日歷分配了未修改的控制模板時,這會在VS2008和Blend 3.0中導致異常,如下面的XAML中所述。

我不能完全弄清楚如何修改控件模板以消除該錯誤,而不是刪除鼠標懸停突出顯示。我想保留它,但我看不到什麼TextColor屬性應該指向。有什麼建議麼?謝謝你的幫助!





XAML標記


<Window 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:Custom="http://schemas.microsoft.com/wpf/2008/toolkit" 
    x:Class="WpfApplication1.MainWindow" 
    x:Name="Window" 
    Title="MainWindow" 
    Width="640" Height="480"> 
    <Window.Resources> 
     <Style x:Key="CalendarStyle1" TargetType="{x:Type Custom:Calendar}"> 
      <Setter Property="Foreground" Value="#FF333333"/> 
      <Setter Property="Background"> 
       <Setter.Value> 
        <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0"> 
         <GradientStop Color="#FFE4EAF0" Offset="0"/> 
         <GradientStop Color="#FFECF0F4" Offset="0.16"/> 
         <GradientStop Color="#FFFCFCFD" Offset="0.16"/> 
         <GradientStop Color="White" Offset="1"/> 
        </LinearGradientBrush> 
       </Setter.Value> 
      </Setter> 
      <Setter Property="BorderBrush"> 
       <Setter.Value> 
        <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0"> 
         <GradientStop Color="#FFA3AEB9" Offset="0"/> 
         <GradientStop Color="#FF8399A9" Offset="0.375"/> 
         <GradientStop Color="#FF718597" Offset="0.375"/> 
         <GradientStop Color="#FF617584" Offset="1"/> 
        </LinearGradientBrush> 
       </Setter.Value> 
      </Setter> 
      <Setter Property="BorderThickness" Value="1"/> 
      <Setter Property="Template"> 
       <Setter.Value> 
        <ControlTemplate TargetType="{x:Type Custom:Calendar}"> 
         <StackPanel x:Name="PART_Root" HorizontalAlignment="Center"> 
          <Custom:CalendarItem x:Name="PART_CalendarItem" Style="{DynamicResource CalendarItemStyle1}" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}"/> 
         </StackPanel> 
        </ControlTemplate> 
       </Setter.Value> 
      </Setter> 
     </Style> 
     <Style x:Key="CalendarItemStyle1" TargetType="{x:Type Custom:CalendarItem}"> 
      <Setter Property="Margin" Value="0,3"/> 
      <Setter Property="Template"> 
       <Setter.Value> 
        <ControlTemplate TargetType="{x:Type Custom:CalendarItem}"> 
         <ControlTemplate.Resources> 
          <DataTemplate x:Key="DayTitleTemplate"> 
           <TextBlock HorizontalAlignment="Center" Margin="0,6" VerticalAlignment="Center" FontFamily="Verdana" FontSize="9.5" FontWeight="Bold" Foreground="#FF333333" Text="{Binding}"/> 
          </DataTemplate> 
         </ControlTemplate.Resources> 
         <Grid x:Name="PART_Root"> 
          <Grid.Resources> 
           <SolidColorBrush x:Key="DisabledColor" Color="#A5FFFFFF"/> 
          </Grid.Resources> 
          <VisualStateManager.VisualStateGroups> 
           <VisualStateGroup x:Name="CommonStates"> 
            <VisualState x:Name="Normal"/> 
            <VisualState x:Name="Disabled"> 
             <Storyboard> 
              <DoubleAnimation Duration="00:00:00" Storyboard.TargetName="PART_DisabledVisual" Storyboard.TargetProperty="Opacity" To="1"/> 
             </Storyboard> 
            </VisualState> 
           </VisualStateGroup> 
          </VisualStateManager.VisualStateGroups> 
          <Border Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" CornerRadius="1"> 
           <Border BorderBrush="White" BorderThickness="2" CornerRadius="1"> 
            <Grid> 
             <Grid.Resources> 
              <ControlTemplate x:Key="HeaderButtonTemplate" TargetType="{x:Type Button}"> 
               <Grid Cursor="Hand"> 
                <VisualStateManager.VisualStateGroups> 
                 <VisualStateGroup x:Name="CommonStates"> 
                  <VisualState x:Name="Normal"/> 
                  <VisualState x:Name="MouseOver"> 
                   <Storyboard> 
                    <ColorAnimation Duration="00:00:00" Storyboard.TargetName="TextColor" Storyboard.TargetProperty="Color" To="#FF73A9D8"/> <!-- EXCEPTION --> 
                   </Storyboard> 
                  </VisualState> 
                  <VisualState x:Name="Disabled"> 
                   <Storyboard> 
                    <DoubleAnimation Duration="00:00:00" Storyboard.TargetName="buttonContent" Storyboard.TargetProperty="Opacity" To="0.5"/> 
                   </Storyboard> 
                  </VisualState> 
                 </VisualStateGroup> 
                </VisualStateManager.VisualStateGroups> 
                <ContentPresenter x:Name="buttonContent" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="1,4,1,9" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" TextElement.Foreground="#FF333333" Content="{TemplateBinding Content}" ContentTemplate="{TemplateBinding ContentTemplate}"/> 
               </Grid> 
              </ControlTemplate> 
              <ControlTemplate x:Key="NextButtonTemplate" TargetType="{x:Type Button}"> 
               <Grid Cursor="Hand"> 
                <VisualStateManager.VisualStateGroups> 
                 <VisualStateGroup x:Name="CommonStates"> 
                  <VisualState x:Name="Normal"/> 
                  <VisualState x:Name="MouseOver"> 
                   <Storyboard> 
                    <ColorAnimation Duration="00:00:00" Storyboard.TargetName="TextColor" Storyboard.TargetProperty="Color" To="#FF73A9D8"/> 
                   </Storyboard> 
                  </VisualState> 
                  <VisualState x:Name="Disabled"> 
                   <Storyboard> 
                    <DoubleAnimation Duration="00:00:00" Storyboard.TargetName="TextColor" Storyboard.TargetProperty="Opacity" To="0.5"/> 
                   </Storyboard> 
                  </VisualState> 
                 </VisualStateGroup> 
                </VisualStateManager.VisualStateGroups> 
                <Rectangle Fill="#11E5EBF1" Stretch="Fill" Opacity="1"/> 
                <Grid> 
                 <Path Fill="#FF333333" Stretch="Fill" HorizontalAlignment="Right" Margin="0,-6,14,0" VerticalAlignment="Center" Width="6" Height="10" Data="M282.875,231.875L282.875,240.375 288.625,236z"/> 
                </Grid> 
               </Grid> 
              </ControlTemplate> 
              <ControlTemplate x:Key="PreviousButtonTemplate" TargetType="{x:Type Button}"> 
               <Grid Cursor="Hand"> 
                <VisualStateManager.VisualStateGroups> 
                 <VisualStateGroup x:Name="CommonStates"> 
                  <VisualState x:Name="Normal"/> 
                  <VisualState x:Name="MouseOver"> 
                   <Storyboard> 
                    <ColorAnimation Duration="00:00:00" Storyboard.TargetName="TextColor" Storyboard.TargetProperty="Color" To="#FF73A9D8"/> 
                   </Storyboard> 
                  </VisualState> 
                  <VisualState x:Name="Disabled"> 
                   <Storyboard> 
                    <DoubleAnimation Duration="00:00:00" Storyboard.TargetName="TextColor" Storyboard.TargetProperty="Opacity" To="0.5"/> 
                   </Storyboard> 
                  </VisualState> 
                 </VisualStateGroup> 
                </VisualStateManager.VisualStateGroups> 
                <Rectangle Fill="#11E5EBF1" Stretch="Fill" Opacity="1"/> 
                <Grid> 
                 <Path Fill="#FF333333" Stretch="Fill" HorizontalAlignment="Left" Margin="14,-6,0,0" VerticalAlignment="Center" Width="6" Height="10" Data="M288.75,232.25L288.75,240.625 283,236.625z"/> 
                </Grid> 
               </Grid> 
              </ControlTemplate> 
             </Grid.Resources> 
             <Grid.ColumnDefinitions> 
              <ColumnDefinition Width="Auto"/> 
              <ColumnDefinition Width="Auto"/> 
              <ColumnDefinition Width="Auto"/> 
             </Grid.ColumnDefinitions> 
             <Grid.RowDefinitions> 
              <RowDefinition Height="Auto"/> 
              <RowDefinition Height="*"/> 
             </Grid.RowDefinitions> 
             <Button x:Name="PART_PreviousButton" HorizontalAlignment="Left" Width="28" Height="20" Focusable="False" Grid.Column="0" Grid.Row="0"> 
              <Button.Template> 
               <ControlTemplate TargetType="{x:Type Button}"> 
                <Grid Cursor="Hand"> 
                 <VisualStateManager.VisualStateGroups> 
                  <VisualStateGroup x:Name="CommonStates"> 
                   <VisualState x:Name="Normal"/> 
                   <VisualState x:Name="MouseOver"> 
                    <Storyboard> 
                     <ColorAnimation Duration="00:00:00" Storyboard.TargetName="TextColor" Storyboard.TargetProperty="Color" To="#FF73A9D8"/> 
                    </Storyboard> 
                   </VisualState> 
                   <VisualState x:Name="Disabled"> 
                    <Storyboard> 
                     <DoubleAnimation Duration="00:00:00" Storyboard.TargetName="TextColor" Storyboard.TargetProperty="Opacity" To="0.5"/> 
                    </Storyboard> 
                   </VisualState> 
                  </VisualStateGroup> 
                 </VisualStateManager.VisualStateGroups> 
                 <Rectangle Fill="#11E5EBF1" Stretch="Fill" Opacity="1"/> 
                 <Grid> 
                  <Path Fill="#FF333333" Stretch="Fill" HorizontalAlignment="Left" Margin="14,-6,0,0" VerticalAlignment="Center" Width="6" Height="10" Data="M288.75,232.25L288.75,240.625 283,236.625z"/> 
                 </Grid> 
                </Grid> 
               </ControlTemplate> 
              </Button.Template> 
             </Button> 
             <Button x:Name="PART_HeaderButton" HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="10.5" FontWeight="Bold" Focusable="False" Grid.Column="1" Grid.Row="0" Template="{DynamicResource ButtonControlTemplate1}"/> 
             <Button x:Name="PART_NextButton" HorizontalAlignment="Right" Width="28" Height="20" Focusable="False" Grid.Column="2" Grid.Row="0"> 
              <Button.Template> 
               <ControlTemplate TargetType="{x:Type Button}"> 
                <Grid Cursor="Hand"> 
                 <VisualStateManager.VisualStateGroups> 
                  <VisualStateGroup x:Name="CommonStates"> 
                   <VisualState x:Name="Normal"/> 
                   <VisualState x:Name="MouseOver"> 
                    <Storyboard> 
                     <ColorAnimation Duration="00:00:00" Storyboard.TargetName="TextColor" Storyboard.TargetProperty="Color" To="#FF73A9D8"/> 
                    </Storyboard> 
                   </VisualState> 
                   <VisualState x:Name="Disabled"> 
                    <Storyboard> 
                     <DoubleAnimation Duration="00:00:00" Storyboard.TargetName="TextColor" Storyboard.TargetProperty="Opacity" To="0.5"/> 
                    </Storyboard> 
                   </VisualState> 
                  </VisualStateGroup> 
                 </VisualStateManager.VisualStateGroups> 
                 <Rectangle Fill="#11E5EBF1" Stretch="Fill" Opacity="1"/> 
                 <Grid> 
                  <Path Fill="#FF333333" Stretch="Fill" HorizontalAlignment="Right" Margin="0,-6,14,0" VerticalAlignment="Center" Width="6" Height="10" Data="M282.875,231.875L282.875,240.375 288.625,236z"/> 
                 </Grid> 
                </Grid> 
               </ControlTemplate> 
              </Button.Template> 
             </Button> 
             <Grid x:Name="PART_MonthView" Margin="6,-1,6,6" Visibility="Visible" Grid.ColumnSpan="3" Grid.Row="1"> 
              <Grid.ColumnDefinitions> 
               <ColumnDefinition Width="Auto"/> 
               <ColumnDefinition Width="Auto"/> 
               <ColumnDefinition Width="Auto"/> 
               <ColumnDefinition Width="Auto"/> 
               <ColumnDefinition Width="Auto"/> 
               <ColumnDefinition Width="Auto"/> 
               <ColumnDefinition Width="Auto"/> 
              </Grid.ColumnDefinitions> 
              <Grid.RowDefinitions> 
               <RowDefinition Height="Auto"/> 
               <RowDefinition Height="Auto"/> 
               <RowDefinition Height="Auto"/> 
               <RowDefinition Height="Auto"/> 
               <RowDefinition Height="Auto"/> 
               <RowDefinition Height="Auto"/> 
               <RowDefinition Height="Auto"/> 
              </Grid.RowDefinitions> 
             </Grid> 
             <Grid x:Name="PART_YearView" Margin="6,-3,7,6" Visibility="Hidden" Grid.ColumnSpan="3" Grid.Row="1"> 
              <Grid.ColumnDefinitions> 
               <ColumnDefinition Width="Auto"/> 
               <ColumnDefinition Width="Auto"/> 
               <ColumnDefinition Width="Auto"/> 
               <ColumnDefinition Width="Auto"/> 
              </Grid.ColumnDefinitions> 
              <Grid.RowDefinitions> 
               <RowDefinition Height="Auto"/> 
               <RowDefinition Height="Auto"/> 
               <RowDefinition Height="Auto"/> 
              </Grid.RowDefinitions> 
             </Grid> 
            </Grid> 
           </Border> 
          </Border> 
          <Rectangle x:Name="PART_DisabledVisual" Fill="#A5FFFFFF" Stretch="Fill" Stroke="#A5FFFFFF" StrokeThickness="1" RadiusX="2" RadiusY="2" Opacity="0" Visibility="Collapsed"/> 
         </Grid> 
         <ControlTemplate.Triggers> 
          <Trigger Property="IsEnabled" Value="False"> 
           <Setter Property="Visibility" TargetName="PART_DisabledVisual" Value="Visible"/> 
          </Trigger> 
          <DataTrigger Binding="{Binding DisplayMode, RelativeSource={RelativeSource FindAncestor, AncestorLevel=1, AncestorType={x:Type Custom:Calendar}}}" Value="Year"> 
           <Setter Property="Visibility" TargetName="PART_MonthView" Value="Hidden"/> 
           <Setter Property="Visibility" TargetName="PART_YearView" Value="Visible"/> 
          </DataTrigger> 
          <DataTrigger Binding="{Binding DisplayMode, RelativeSource={RelativeSource FindAncestor, AncestorLevel=1, AncestorType={x:Type Custom:Calendar}}}" Value="Decade"> 
           <Setter Property="Visibility" TargetName="PART_MonthView" Value="Hidden"/> 
           <Setter Property="Visibility" TargetName="PART_YearView" Value="Visible"/> 
          </DataTrigger> 
         </ControlTemplate.Triggers> 
        </ControlTemplate> 
       </Setter.Value> 
      </Setter> 
     </Style> 
     <ControlTemplate x:Key="ButtonControlTemplate1" TargetType="{x:Type Button}"> 
      <Grid Cursor="Hand"> 
       <VisualStateManager.VisualStateGroups> 
        <VisualStateGroup x:Name="CommonStates"> 
         <VisualState x:Name="Normal"/> 
         <VisualState x:Name="MouseOver"> 
          <Storyboard> 
           <ColorAnimation Duration="00:00:00" Storyboard.TargetName="TextColor" Storyboard.TargetProperty="Color" To="#FF73A9D8"/> 
          </Storyboard> 
         </VisualState> 
         <VisualState x:Name="Disabled"> 
          <Storyboard> 
           <DoubleAnimation Duration="00:00:00" Storyboard.TargetName="buttonContent" Storyboard.TargetProperty="Opacity" To="0.5"/> 
          </Storyboard> 
         </VisualState> 
        </VisualStateGroup> 
       </VisualStateManager.VisualStateGroups> 
       <ContentPresenter x:Name="buttonContent" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="1,4,1,9" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" TextElement.Foreground="#FF333333" Content="{TemplateBinding Content}" ContentTemplate="{TemplateBinding ContentTemplate}"/> 
      </Grid> 
     </ControlTemplate> 
    </Window.Resources> 

    <Grid x:Name="LayoutRoot"> 
     <Custom:Calendar HorizontalAlignment="Left" VerticalAlignment="Top" Style="{DynamicResource CalendarStyle1}"/> 
    </Grid> 
</Window> 
+1

如果這是一個bug,它可能是團隊應該看的東西。你有沒有考慮在Silverlight.net的論壇上發帖? –

+0

做了第一件事。現在我需要弄清楚如何修復控制模板,所以我可以做一些簡單的修改。 –

回答

5

我們剛剛經歷過的工作同樣的事情。這看起來並不是WPFToolkit中的一個bug,相反,Expression Blend存在一個問題,因爲創建原始模板的人變得有點棘手。

首先,去抓取默認模板。如果你下載源代碼,他們將在Toolkit-Release/Calendar/Themes/Generic.xaml中。源可以在WPF Toolkit CodePlex站點上找到。 http://wpf.codeplex.com/

的CalendarItemTemplate有這類的設置的:

<Style TargetType="primitives:CalendarItem"> 
... 
<Setter Property="Template"> 
    <Setter.Value> 
     <ControlTemplate TargetType="primitives:CalendarItem"> 
      ... 
      <Grid Name="PART_Root" > 
       <Border 
        ... 
        <Border CornerRadius="1" BorderBrush="#FFFFFFFF" BorderThickness="2"> 
         <Grid> 
          <Grid.Resources> 
           <ControlTemplate x:Key="HeaderButtonTemplate" TargetType="Button"> 
          ... 
          <Button x:Name="PART_HeaderButton" Template="{StaticResource HeaderButtonTemplate}"  
          ... 

這是原來的HeaderButtonTemplate:

<ControlTemplate x:Key="HeaderButtonTemplate" TargetType="Button"> 
    <Grid Cursor="Hand"> 
     <vsm:VisualStateManager.VisualStateGroups> 
      <vsm:VisualStateGroup x:Name="CommonStates"> 
       <vsm:VisualState x:Name="Normal" /> 
       <vsm:VisualState x:Name="MouseOver"> 
        <Storyboard> 
         <ColorAnimation Storyboard.TargetName="TextColor" Storyboard.TargetProperty="Color" To="#FF73A9D8" Duration="0" /> 
        </Storyboard> 
       </vsm:VisualState> 
       <vsm:VisualState x:Name="Disabled"> 
        <Storyboard> 
         <DoubleAnimation Storyboard.TargetName="buttonContent" Storyboard.TargetProperty="Opacity" To=".5" Duration="0" /> 
        </Storyboard> 
       </vsm:VisualState> 
      </vsm:VisualStateGroup> 
     </vsm:VisualStateManager.VisualStateGroups> 
     <ContentPresenter 
      x:Name="buttonContent" 
      Content="{TemplateBinding Content}" 
      ContentTemplate="{TemplateBinding ContentTemplate}" 
      Margin="1,4,1,9" 
      HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" 
      VerticalAlignment="{TemplateBinding VerticalContentAlignment}"> 
      <TextElement.Foreground> 
       <SolidColorBrush x:Name="TextColor" Color="#FF333333"/> 
      </TextElement.Foreground> 
     </ContentPresenter> 
    </Grid> 
</ControlTemplate> 

我們關注的部分是在這裏:

<ContentPresenter 
    x:Name="buttonContent" 
    Content="{TemplateBinding Content}" 
    ContentTemplate="{TemplateBinding ContentTemplate}" 
    Margin="1,4,1,9" 
    HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" 
    VerticalAlignment="{TemplateBinding VerticalContentAlignment}"> 
    <TextElement.Foreground> 
     <SolidColorBrush x:Name="TextColor" Color="#FF333333"/> 
    </TextElement.Foreground> 
</ContentPresenter> 

注意TextElement附加屬性實例化SolidColorBrush的etter。這是故事板定位的命名筆刷。

當您在Blend中執行「編輯模板副本」時,它會內聯一些模板,以便直接設置Header按鈕模板,而不是將其包含在網格資源中。

<Button x:Name="PART_HeaderButton" HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="10.5" FontWeight="Bold" Focusable="False" Grid.Column="1" Grid.Row="0"> 
<Button.Template> 
    <ControlTemplate TargetType="{x:Type Button}"> 
    <Grid Cursor="Hand"> 

我不知道爲什麼這樣做,當我編輯模板我期待模板的實際副本的副本。我想我明白,有時候模板是從外部引用的,但在這種情況下並不是 - 即使它是完整的複製並將其添加到樣式/控件模板資源似乎更加謹慎。更糟的是,作爲再加工共混物的一部分修改contentpresenter定義模板,把它變成這樣:

<ContentPresenter x:Name="buttonContent" 
    HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" 
    Margin="1,4,1,9" 
    VerticalAlignment="{TemplateBinding VerticalContentAlignment}" 
    ContentTemplate="{TemplateBinding ContentTemplate}" 
    Content="{TemplateBinding Content}" 
    TextElement.Foreground="#FF333333" /> 

所以,換句話說,沒有更多的命名畫筆,故事板的目標是不正確現在。

幸運的是修復很容易 - 使用原始模板作爲您的出發點。麻煩的是,混合不喜歡它,並且不會顯示,因爲由於某種原因,它只能將contentpresenter上的這個附加屬性設置爲開始標記的一部分,而不是擴展模式或任何它所調用的內容。當然,可能很有可能以另一種更融合的方式複製功能。

編輯:這是一個快速的方法來破解模板,使其融合。它確實是一個黑客,但大部分是無害的。我不主張通常這樣做,但它似乎工作正常。

<ControlTemplate x:Key="HeaderButtonTemplate" TargetType="Button"> 
    <Grid Cursor="Hand"> 
     <vsm:VisualStateManager.VisualStateGroups> 
      <vsm:VisualStateGroup x:Name="CommonStates"> 
       <vsm:VisualState x:Name="Normal" /> 
       <vsm:VisualState x:Name="MouseOver"> 
        <Storyboard> 
         <ColorAnimation Storyboard.TargetName="TextColor" Storyboard.TargetProperty="Color" To="#FF73A9D8" Duration="0" /> 
        </Storyboard> 
       </vsm:VisualState> 
       <vsm:VisualState x:Name="Disabled"> 
        <Storyboard> 
         <DoubleAnimation Storyboard.TargetName="buttonContent" Storyboard.TargetProperty="Opacity" To=".5" Duration="0" /> 
        </Storyboard> 
       </vsm:VisualState> 
      </vsm:VisualStateGroup> 
     </vsm:VisualStateManager.VisualStateGroups> 
     <!-- A dummy Rectangle that is essentially a container for the TextColor brush --> 
     <Rectangle Width="0" Height="0"> 
      <Rectangle.Fill> 
       <SolidColorBrush x:Name="TextColor" Color="#FF333333"/> 
      </Rectangle.Fill> 
     </Rectangle> 
     <ContentPresenter 
       x:Name="buttonContent" 
       Content="{TemplateBinding Content}" 
       ContentTemplate="{TemplateBinding ContentTemplate}" 
       Margin="1,4,1,9" 
       HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" 
       VerticalAlignment="{TemplateBinding VerticalContentAlignment}" 
       TextElement.Foreground="{Binding ElementName=TextColor}"> 
     </ContentPresenter> 
    </Grid> 
</ControlTemplate> 

它的essense是容納刷得像另一個對象的一部分 - 如果太小,在技術上可見的顯示出來,然後做對contentpresenter有約束力的 - 因爲它是在開放標籤混合做沒有按」 t抱怨。是的,我知道,這種氣味,但它是原始模板的最小重寫,我可以看到它的工作。

+0

接受*和* upvote。感謝您解答一個棘手的問題! –

+0

作爲Expression Blend反饋頁面上的一個錯誤提交:https://connect.microsoft.com/Expression/feedback/ViewFeedback.aspx?FeedbackID=495224 –

+0

歡迎 - 我編輯了我的答案,提供了一種快速和骯髒的方式使其融合。 – Egor