wpf setting control hierarchy problem topmost bottom bottom

problems encountered

The button control cannot be clicked. It is guessed that it is a problem with the order of the controls, which is covered by a statistical chart control next to it. As shown in the figure, the radio button is covered by the chart control.
insert image description here
There is only one solution found on the Internet, which has been frantically copied by countless websites. The method is extremely cumbersome and needs to traverse the entire control tree. Helpless, I can search in English by myself, and I don’t need to use Google. Bing International Version can search in English. I found a reliable solution without seeing a few, and I hope that when you encounter problems, you can carry the answers from the English Internet. (Everyone has an answer in 10 years, and the Chinese Internet has no answer in 22 years, alas)
insert image description here
https://social.msdn.microsoft.com/Forums/vstudio/en-US/40cce1d7-a6f0-4564-8f02-e39b3ee56a2b/wpf -control-whos-on-top-?forum=wpf#:~:text=As%20far%20as%20I%20know%20WPF%20renders%20controls,Button%20control%20will%20be%20on%20top%20of%20TextBlock .

solution

WPF controls the hierarchy according to the order of controls, and the controls written later will be arranged at the upper level.
Code before adjustment:

<!-- 两个单选框控件 -->
<RadioButton Grid.Column="0" GroupName="PieChartType" Content="大小" Margin="380,10,0,0"
             Click="RadioButtonSize_OnClick" IsChecked="True" Style="{ 
        StaticResource pie-char-type}"/>
<RadioButton Grid.Column="0" GroupName="PieChartType" Content="占用空间" Margin="380,30,0,0"
             Click="RadioButtonSpaceUsage_OnClick" Style="{ 
        StaticResource pie-char-type}"/>
<!-- 统计图控件 -->
<lvc:PieChart Grid.Column="0" x:Name="incidentPieChart" LegendPosition="Bottom"
              ChartPointPointerDown="IncidentPieChart_OnChartPointPointerDown"/>

Adjusted code:

<!-- 统计图控件 -->
<lvc:PieChart Grid.Column="0" x:Name="incidentPieChart" LegendPosition="Bottom"
              ChartPointPointerDown="IncidentPieChart_OnChartPointPointerDown"/>
<!-- 两个单选框控件 -->
<RadioButton Grid.Column="0" GroupName="PieChartType" Content="大小" Margin="380,10,0,0"
             Click="RadioButtonSize_OnClick" IsChecked="True" Style="{ 
        StaticResource pie-char-type}"/>
<RadioButton Grid.Column="0" GroupName="PieChartType" Content="占用空间" Margin="380,30,0,0"
             Click="RadioButtonSpaceUsage_OnClick" Style="{ 
        StaticResource pie-char-type}"/>

The button is clickable after adjustment.

Guess you like

Origin blog.csdn.net/weixin_44927769/article/details/127214845