0

This is an example of how I make my checkboxes:

<CheckBox x:Name="Ekm" Checked="Check" Unchecked="UnCheck">
    <CheckBox.Content>
        <TextBlock>
            <Hyperlink RequestNavigate="Hyperlink_RequestNavigate" NavigateUri="[REDACTED]">
                Banking History
            </Hyperlink>
        </TextBlock>
    </CheckBox.Content>
</CheckBox>

And the code-behind:

foreach (var checkbox in listview.Items)
{
    if (checkbox is CheckBox cb)
    {
        if (cb.Name.StartsWith("Sa"))
        {
            SelectAllCheckBoxes.Add(cb);
        }
        else
        {
            AllCheckBoxes.Add(cb);
        }
    }
}

And the moment I try to read the content (Specifically the words "Banking History"):

foreach (var cb in AllCheckBoxes)
{
     NameCompareTuples.Add(new Tuple<string, string>(cb.Name, cb.Content.ToString()));
}

The above code, and many variations I've tried (Casting as TextBlocks and such, thus not needing ".ToString();"), simply return an empty string, or if I apply ".ToString();" it passes something along the lines of:

"System.Windows.Controls.TextBlock" 
  • I search and try to find an example on LogicalTreeHelper, that enables you to get an element’s children/parent in a recursive way and so find the inner hyperlink... but after a while I think it is a better idea to use data binding in your code, that you only need to define the data template once, and work with the data model directly. – kennyzx Sep 06 '18 at 11:23
  • Is [this answer](https://stackoverflow.com/a/10279201/815938) helpful? – kennyzx Sep 06 '18 at 11:37
  • Use Inlines collection -> (Run((Hyperlink)(cb.Content.Inlines.First())).Inlines).First() – Babbillumpa Sep 06 '18 at 13:11

0 Answers0