我在参考资料中有以下xaml代码:
<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是在另一个分部类定义中定义的DP。
当我在StackPanel或ListBox中添加一种物质时,没有显示任何内容:
Substance s = new Substance("newSub", 100, symTable);
substancePanel.Children.Add(s);有人能告诉我我哪里做错了吗?任何帮助都将不胜感激。
发布于 2012-01-27 04:02:42
我不是告诉过您不要让Substance继承UI相关的类吗?
如果忽略了这一点,DataTemplates将不会被应用(取决于预期的类型),但比这更糟糕的是,您打破了模型-视图-分离。
https://stackoverflow.com/questions/9024464
复制相似问题