We all know that window has multiple themes (Theme). Under normal circumstances, obviously we would like to have different themes, the behavior of our application will not change. Or, we don't want to write specific logic for the control for a particular topic. Unfortunately, there are problems with some of the controls in the. NET framework, so that we have to deal specifically with the control under specific topics when we use it.
Let me give you an example. Putting a checkbox in a ListBox, forming a checkboxlist should be a more common application. In theory, the easiest way to do this in WPF is to put a checkbox in the ItemTemplate of the ListBox or in the Itemcontainerstyle.
But in fact, when you do this simple CheckBoxList, you will encounter one problem after another. First of all, to reiterate the intent of the text, fearing that they did not explain the white misleading.
This article is not a discussion
CheckBoxList
The blue bar in question, but in the discussion checkbox
The problem of different behaviors under different topics. CheckBoxList
is just an example.
Take a look at the effect chart first.
Figure 1. A checkbox under two themes
In the above illustration, the left side is a checkbox under the classic theme. On the right is the CheckBox under the XP default Luna theme.
Question 1. The ischecked state of the checkbox is out of sync with the isselected state of the ListBoxItem. If you want to keep the blue bar selected, then it is easier to do, the two attributes binding together on it. If you don't want the blue bar that was selected, it's a little bit more complicated. There are many solutions, so don't go into it. In the sample program, the problem is not resolved in order to reduce interference.
Question 2. When the item on the checkbox is selected, it is blue. The text in the checkbox is black, which is inconsistent with the default color behavior of the ListBoxItem. In order for a checkbox to be white when selected, it is not difficult to write a binding. This is not a problem at all, but to solve this problem, the following problems are the main problem. (Of course, if you hide the blue bar, there's no problem.) )
Question 3. This is the main topic of this article, look at the following pictures to know. We do the same thing on both sides of the CheckBoxList. First come to the right.
Figure 2. Select the Last checkbox
Figure 3. Click the blank on the side of the checkbox just now to select it