InitializeComponent InvalidCastExeption

时间:2013-09-13 10:55:17

标签: c# wpf silverlight listbox itemscontrol

在我的应用中,我有一个ListBox,我已将其设置为ItemTemplate,而且工作正常。但在遇到一些问题后,我决定将ListBox更改为ItemsControl, 所以我刚刚用ListBox更改了ItemsControl关键字,(我不知道是否允许)。但是当我运行该应用时,InvalidCastExeption上的InitializeComponent已取消联系。

我还是编程新手,所以有人可以帮我解决这个问题吗?

编辑:

<ListBox Name="ChannelsSearchResaultList" Visibility="Collapsed" Grid.Row="1">
    <ListBox.ItemTemplate>
        <DataTemplate>
            <Border Name="ChannelContainer" Margin="5" Width="470" 
                HorizontalAlignment="Stretch" BorderBrush="BlueViolet" 
                BorderThickness="2" Background="#FF1D1D1D" MouseLeftButtonDown=
                "Border_MouseLeftButtonDown" MouseLeftButtonUp=
                "ChannelContainer_MouseLeftButtonUp">
                <Grid Height="110">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition/>
                        <ColumnDefinition Width="340"/>
                    </Grid.ColumnDefinitions>
                    <Image Source="{Binding Logo}"  Margin="5"/>
                    <TextBlock Text="{Binding Duration}"  Margin="10,5" 
                        VerticalAlignment="Bottom" HorizontalAlignment="Right"/>
                    <Canvas Grid.Column="1" >
                        <TextBlock Text="{Binding Title}" FontWeight="Bold" 
                            Foreground="Red"/>
                        <TextBlock Text="{Binding Views}" Canvas.Top="60" 
                            Canvas.Left="20" />
                    </Canvas>
                </Grid>
            </Border>
        </DataTemplate>
    </ListBox.ItemTemplate>
</ListBox>

0 个答案:

没有答案