但是有一个问题,所有项目都位于0,0.我测试了Bindings他们没有返回0,0.
我如何使这项工作,以便项目位于正确的位置?
也可以在画布上创建2个图层,每个图层绑定到不同的源,并使用不同的模板?
这是在Silverlight中
<ItemsControl GrID.Row="1" GrID.Column="1" WIDth="650" Height="650" ItemsSource="{Binding Skills}"> <ItemsControl.ItemsPanel> <ItemsPanelTemplate> <Canvas margin="0" WIDth="650" Height="650" /> </ItemsPanelTemplate> </ItemsControl.ItemsPanel> <ItemsControl.ItemTemplate> <DataTemplate> <StackPanel Canvas.top="{Binding top}" Canvas.left="{Binding left}"> <TextBlock Text="{Binding name}" /> <Image Source="{Binding Icon}" /> <StackPanel OrIEntation="Horizontal" > <TextBlock FontWeight="Bold" TextAlignment="Center" Text="{Binding SkillPointsstatusText}" /> </StackPanel> </StackPanel> </DataTemplate> </ItemsControl.ItemTemplate></ItemsControl>
使用ItemContainerStyle进行测试
<ItemsControl GrID.Row="1" GrID.Column="1" WIDth="650" Height="650" ItemsSource="{Binding Skills}"> <ItemsControl.ItemsPanel> <ItemsPanelTemplate> <Canvas margin="0" WIDth="650" Height="650" /> </ItemsPanelTemplate> </ItemsControl.ItemsPanel> <ItemsControl.ItemTemplate> <DataTemplate> <StackPanel> <TextBlock Text="{Binding name}" /> <Image Source="{Binding Icon}" /> <TextBlock FontWeight="Bold" TextAlignment="Center" Text="{Binding SkillPointsstatusText}" /> </StackPanel> </DataTemplate> </ItemsControl.ItemTemplate> <ItemsControl.ItemContainerStyle> <Style> <Setter Property="Canvas.top" Value="{Binding top}" /> <Setter Property="Canvas.left" Value="{Binding left}" /> </Style> </ItemsControl.ItemContainerStyle></ItemsControl>
好吧,我已经下了项目,但如果一个人有一个回答,我会把问题留下来
解决方法 以下所有内容在SL4中都不起作用,因为它依赖于Setter.Value中的绑定.尝试在ItemContainerStyle中设置绑定,因为StackPanel不是根元素;您的模板将放置在ContentPresenter中,因此将忽略StackPanel中画布定位的附加属性.
<ItemsControl.ItemContainerStyle> <Style> <Setter Property="Canvas.top" Value="{Binding top}" /> <Setter Property="Canvas.left" Value="{Binding left}" /> </Style></ItemsControl.ItemContainerStyle>
编辑:如果Silverlight不支持ItemContainerStyle,您可以为ContentPresenters设置通用样式,它也可以正常工作:
<ItemsControl ItemsSource="{Binding Data}"> <ItemsControl.Resources> <Style targettype="ContentPresenter"> <Setter Property="Canvas.left" Value="{Binding left}"/> <Setter Property="Canvas.top" Value="{Binding top}"/> </Style> </ItemsControl.Resources> <ItemsControl.ItemsPanel> <ItemsPanelTemplate> <Canvas/> </ItemsPanelTemplate> </ItemsControl.ItemsPanel> <ItemsControl.ItemTemplate> <DataTemplate> ... </DataTemplate> </ItemsControl.ItemTemplate> </ItemsControl>总结
以上是内存溢出为你收集整理的wpf – Silverlight中的Canvas绑定全部内容,希望文章能够帮你解决wpf – Silverlight中的Canvas绑定所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)