2012-04-08 58 views
0

我想给设置值绑定到属性,但我不断收到灾难性错误0x8000ffff的Silverlight在样式的绑定问题

尝试这样:

​​

那么这个:

<ItemsControl.Style> 
    <Style TargetType="ContentPresenter"> 
     <Setter Property="Grid.Row" 
       Value="0" /> 
     <Setter Property="Grid.Column" 
       Value="0" /> 
    </Style> 
</ItemsControl.Style> 

我不得不升级到SL5来获取TargetType。第二个示例删除了任何绑定的尝试,但仍“失败”。

<ItemsControl.ItemsPanel> 
    <ItemsPanelTemplate> 
     <layout:MatrixGrid /> 
    </ItemsPanelTemplate> 
</ItemsControl.ItemsPanel> 

我试图创建数据的网格矩阵(如由其他人在一个例子说明)。

ItemsControl(在Silverlight中)没有ItemContainerStyle元素,所以我尝试了这一点,至今没有运气。

<ListBox.ItemsPanel> 
    <ItemsPanelTemplate> 
     <layout:MatrixGrid /> 
    </ItemsPanelTemplate> 
</ListBox.ItemsPanel> 
<ListBox.ItemContainerStyle> 
    <Style TargetType="ContentPresenter"> 
     <Setter Property="Grid.Row" 
       Value="{Binding GridRow}" /> 
     <Setter Property="Grid.Column" 
       Value="{Binding GridColumn}" /> 
    </Style> 
</ListBox.ItemContainerStyle> 
+0

你能展示你使用这种风格的地方吗? – ChrisF 2012-04-08 14:27:28

+0

嗨ChrisF,我在ItemsControl中使用它 – AlwaysLearning 2012-04-08 14:29:46

+0

为什么你使用TargetType =“ContentPresenter”,如果你的风格是ItemsControl? – Zabavsky 2012-04-08 18:03:59

回答

0

Style.TargetType属性设置为它的样式所针对的类型。尝试将其设置为ItemsControl,这可能是它跌倒的原因。

+0

>的WPF示例感谢,我认为ContentPresenter可以在此工作... – AlwaysLearning 2012-04-09 10:40:32