2011-02-25 129 views
0

我創建了一個新的自定義控件,名爲DataGridInsertRowPresenter,它繼承自ContentControl。一切運作良好。自定義ContentControl在模板之後不顯示內容?

然後我添加了新的樣式,它改變了它的模板,它不再顯示內容。這裏是控制:

public class DataGridInsertRowPresenter : ContentControl { 
    static DataGridInsertRowPresenter() { 
     DefaultStyleKeyProperty.OverrideMetadata(typeof(DataGridInsertRowPresenter), new FrameworkPropertyMetadata(typeof(DataGridInsertRowPresenter))); 
    } 
} 

這裏是我的模板:

<Style TargetType="{x:Type Primitives:DataGridInsertRowPresenter}" BasedOn="{StaticResource {x:Type ContentControl}}" > 
    <Setter Property="Template" > 
     <Setter.Value> 
      <ControlTemplate> 
       <ContentPresenter Content="{TemplateBinding Content}" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"/> 
      </ControlTemplate> 
     </Setter.Value> 
    </Setter> 
</Style> 

什麼是錯我的代碼?

+0

你也有這樣爲此嗎?在這種情況下,任何建議的答案都可以標記爲已回答? – bigfoot 2011-11-04 22:37:38

回答

0

可能是因爲您的assemblyinfo.cs缺少一個屬性來告訴它在哪裏尋找資源。檢查你在你的AssemblyInfo.cs以下代碼:

[assembly: ThemeInfo(
ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located 
//(used if a resource is not found in the page, 
// or application resource dictionaries) 
ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located 
//(used if a resource is not found in the page, 
// app, or any theme specific resource dictionaries) 

,並確保您的風格是在主題\ Generic.xaml(或合併字典引用)

0

您需要自Control一個TargetType添加到您的ControlTemplate沒有一個叫Content屬性:

<ControlTemplate TargetType="{x:Type Primitives:DataGridInsertRowPresenter}"> 
相關問題