views:

43

answers:

1

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.

A: 

Nevermind, it should use Path and not ElementName.

rotary_engine