Tag property null when data binding

Posted by rotary_engine on Stack Overflow See other posts from Stack Overflow or by rotary_engine
Published on 2010-04-03T07:32:27Z Indexed on 2010/04/03 7:33 UTC
Read the original article Hit count: 183

Filed under:

Can anyone see what is wrong with this? The Tag property is returning null however the Binding for Id property is definately returning an int value.

    <ListBox ItemsSource="{Binding ElementName=myDomainDataSource, Path=Data}">
        <ListBox.ItemTemplate>
            <DataTemplate>
                <StackPanel Orientation="Horizontal">
                    <TextBlock Text="{Binding Path=Id, Mode=OneWay}" />
                    <HyperlinkButton Content="Edit" Tag="{Binding ElementName=Id, Mode=OneWay}" Click="Edit_Click"  />
                </StackPanel>
            </DataTemplate>
        </ListBox.ItemTemplate>
    </ListBox>

and then...

    private void Edit_Click(object sender, RoutedEventArgs e)
    {
        ContentControl c = sender as ContentControl;

        // exception - c.Tag is null
        int id = (int)c.Tag;
    }

The Id property is showing a value on the UI, but doesn't seem to be getting stored in the buttons Tag property.

© Stack Overflow or respective owner

Related posts about silverlight-4.0