0
我在資源下面XAML代碼:DataTemplate沒有顯示?
<DataTemplate DataType="{x:Type s:Substance}">
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding Name, Mode=TwoWay}" MinWidth="50" MinHeight="20" Background="Blue"/>
<TextBox Text="{Binding Count, Converter={StaticResource stringToIntConverter}, Mode=TwoWay}" MinWidth="50" MinHeight="20" Background="Yellow"/>
</StackPanel>
</DataTemplate>
Substance
從ContentControl
導出:
public partial class Substance : ContentControl
{
string name; public int count; SymbolTable symTable = null;
public Substance(string _name, int _count, SymbolTable _symTable)
{
symTable = _symTable; Name = _name; Count = _count;
}
}
Name
和Count
是另一局部類定義中所定義的DPS。
當我將在StackPanel
或ListBox
什麼物質被所示:
Substance s = new Substance("newSub", 100, symTable);
substancePanel.Children.Add(s);
誰能告訴我什麼,我做錯了。任何幫助,將不勝感激。
Hrrrm我甚至沒有注意到繼承 – Rachel
@Rachel:當我打開這個問題時,我期待它:P –
@ H.B。你是對的,道歉。它在我添加到ListBox時起作用,但是當我將它添加到面板中時,它不會顯示,如果我想同時實現,我應該從ContentControl繼承並提供一個ControlTemplate(作爲附註,控件不能同時擁有一個DataTemplate和一個Controltemplate吧? – mihajlv