jeudi 6 septembre 2018

Get content of Checkbox with Hyperlink as content

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" 




Aucun commentaire:

Enregistrer un commentaire