lundi 29 juin 2015

Programmatically Binding Name ItemsControl

I create programmatically a grid of rectangles and each rectangle has a Label inside it. I detect which rectangle has been clicked using Event Command. My problem is that if I try to bind the rectangle Name I get this error: MarkupExtensions are not allowed for Uid or Name property values, so '{Binding ID}' is not valid So I can retrive the name only if I click on the Label. Is there a solution for this problem? My XAML:

<ItemsControl ItemsSource="{Binding CaskList}" HorizontalAlignment="Left" VerticalAlignment="Top">
                <ItemsControl.ItemsPanel>
                    <ItemsPanelTemplate>
                        <Canvas Width="1680" Height="800">
                            <i:Interaction.Triggers>
                                <i:EventTrigger EventName="MouseLeftButtonDown" >
                                    <cmd:EventToCommand Command="{Binding SelCaskCommand}" PassEventArgsToCommand="True" />
                                </i:EventTrigger>
                            </i:Interaction.Triggers>
                        </Canvas>
                    </ItemsPanelTemplate>
                </ItemsControl.ItemsPanel>
                <ItemsControl.ItemContainerStyle>
                    <Style TargetType="ContentPresenter">
                        <Setter Property="Canvas.Left" Value="{Binding Left}"/>
                        <Setter Property="Canvas.Top" Value="{Binding Top}"/>
                    </Style>
                </ItemsControl.ItemContainerStyle>
                <ItemsControl.ItemTemplate>
                    <DataTemplate>
                        <Grid>
                            <Rectangle Stroke="Black" Width="64" Height="64" Fill="{Binding Color}" ></Rectangle>
                            <Label Content="{Binding ID}" FontSize="14" HorizontalAlignment="Center" VerticalAlignment="Center"/>
                        </Grid>
                    </DataTemplate>
                </ItemsControl.ItemTemplate>
            </ItemsControl>

Aucun commentaire:

Enregistrer un commentaire