在WinJS应用列表视图的itemTemplate
属性可以接受,其中我可以手动创建的元件的功能。模板渲染
哪些是XAML/C#应用这种方法模拟?
我知道DataTemplate中选择,但我需要手动创建的项目,我想摆脱掉因业绩模板。
在WinJS应用列表视图的itemTemplate
属性可以接受,其中我可以手动创建的元件的功能。模板渲染
哪些是XAML/C#应用这种方法模拟?
我知道DataTemplate中选择,但我需要手动创建的项目,我想摆脱掉因业绩模板。
你见过DataTemplateSelector? http://code.msdn.microsoft.com/windowsapps/The-DataTemplateSelector-93e46ad7
使用数据绑定谢谢你,我知道的DataTemplate选择,但我需要手动创建的项目,我想摆脱掉 – Alexander
我想你可以做一个CustomControl自ItemsControl继承。
public class BuildingComparer : ItemsControl
{}
在那里,你会发现一些方法来覆盖:
protected override DependencyObject GetContainerForItemOverride()
{
var container = new ContentPresenter();
//Do Stuff
return container;
}
而且你必须进入项目属性,以便可以画画,每当SizeChanged事件发生的元素,你可以调用一个方法手动绘制所有元素。
希望它可以帮助你。
在C#/ XAML做到这一点,你需要将ItemsControl中的ItemsSource
属性绑定到,为您创建的项目的属性。
例XAML:
<ItemsControl ItemsSource="{Binding SourceProperty}" />
实例的DataContext:
public IEnumerable SourceProperty
{
get
{
yield return new TextBlock(new Run("First"));
yield return new TextBlock(new Run("Second"));
yield return new TextBlock(new Run("Third"));
}
}
编辑: 如果你绝对必须避免所有数据绑定(我不知道你为什么会),您可将ItemsSource
在代码隐藏:
更新XAML:
<ItemsControl Name="MyItemsControl" />
后面的代码:
public MainWindow()
{
InitializeComponent();
MyItemsControl.ItemsSource = SourceProperty;
}
你想要的模板创建功能的C#中的解决方案,使您可以创建动态模板作为winJs?我不清楚这个问题是这样的:) ?? – Anobik
@Anobik是的,但我不想在创建的控制 – Alexander