Problem: Not all of my custom checkboxes are displayed in the same way and it is unclear to me, why.
I have a custom WPF CheckBox
of which I generate instances at runtime.
The custom CheckBox
:
public class CheckBoxQuickSelect : System.Windows.Controls.CheckBox
{
public string Description { get; }
public CheckBoxQuickSelect(string description)
: base()
{
Description = description;
Margin = new Win.Thickness(10, 0, 0, 0);
VerticalAlignment = System.Windows.VerticalAlignment.Center;
VerticalContentAlignment = System.Windows.VerticalAlignment.Center;
Style = (System.Windows.Style)this.FindResource("MySettingsCheckBoxStyle");
}
}
The part where I add the checkboxes at runtime:
foreach (string abbreviation in Helper.TreeSpecies.Keys)
{
CheckBoxQuickSelect cb = new CheckBoxQuickSelect(abbreviation);
cb.Name = Helper.MakeValidXmlName("checkBoxTreeSpecies_" + abbreviation);
cb.Content = abbreviation.Replace("_", "__") + ": " + Helper.TreeSpecies[abbreviation][1];
cb.IsChecked = Helper.TreeSpeciesQuickSelect.Contains(abbreviation);
stackPanelTreeSpecies.Children.Add(cb);
}
The associated style in App.xaml
:
<Style TargetType="CheckBox" x:Key="MySettingsCheckBoxStyle">
<Setter Property="FontSize" Value="12" />
</Style>
There is also a general CheckBox
style earlier in App.xaml
(but it doesn't change anything if I comment that out):
<Style BasedOn="{StaticResource {x:Type CheckBox}}" TargetType="CheckBox">
<Setter Property="FontSize" Value="{DynamicResource StandardFontSize}" />
</Style>
The problem now is: Only the checkboxes with an underscore in their abbreviations get displayed correctly:
Why is that? What can I do to make all boxes look the same?
Aucun commentaire:
Enregistrer un commentaire