Question

I have a list of checkboxes which, when checked, the content (text) should then be strikethrough or even just to change the fontstyle (colour) of the checked item. I'm trying to do this in a checkbox_Tap event handler which is in my codebehind page.

Any ideas as to how I could change the fontstyle or how I could make it strikethough?

Was it helpful?

Solution

The Design Guidelines mention that you should always use the system font unless you have a specific "brand", although there isn't anything forcing you to follow this.

The CheckBox itself, though, has properties you can set in the code-behind for FontFamily, FontSize, FontStretch, FontStyle, Foreground, etc.

In your CheckBox_Tap event handler, you could do something like:

void CheckBox_Tap(object sender, EventArgs e)
{
   CheckBox cb = (CheckBox)sender;
   cb.FontFamily = //<your new font here>
   cb.FontStyle = // <new style here>
}

As for Strikethrough - it doesn't look like there is a built in way to do that (there isn't a specific property for Strikethrough that you can just set to True, for example).

However, I did run across this post, and there is an answer that shows a hacky way to do this in XAML (which I haven't tried) using a Border. I'm wondering if you could try this, and wrap your CheckBox in a Border which is invisible by default, and then make it visible when you want the Strikethrough?

Hope this helps!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top