开发者

Tag property null when data binding

开发者 https://www.devze.com 2022-12-25 06:59 出处:网络
What is wrong with the following? The Tag property is returning null. However, the Binding for Id property is definitely returning an int value.

What is wrong with the following? The Tag property is returning null. However, the Binding for Id property is definitely 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 it doesn't seem to be getting stored in the buttons Tag property.


Nevermind, it should use Path and not ElementName.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号