本帖最后由 qiaoke_song 于 2022-8-16 19:44 编辑
在安装程序里,选择框checkbox的目的只是取得“同意”或“不同意”,将代码文本字符串加入就可以了,见Generated_Style.cs文件
[C#] 纯文本查看 复制代码 public Style Set_CheckBoxStyle(string sKey, string text, string backcolor, string select_color, double height, double fontsize, string fontcolor,int num)
{
string style = @""
<ResourceDictionary xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation' xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'>
<Style x:Key='"" + sKey + @""' TargetType='{x:Type CheckBox}'>
<Setter Property='SnapsToDevicePixels' Value='true' />
<Setter Property='FocusVisualStyle' Value='{DynamicResource CheckBoxFocusVisual}' />
<Setter Property='Height' Value='"" + height + @""'/>
<Setter Property='IsChecked' Value='False'/>
<Setter Property='Margin' Value='0'/>
<Setter Property='Template'>
<Setter.Value>
<ControlTemplate TargetType='CheckBox'>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width='Auto'/>
<ColumnDefinition Width='*'/>
</Grid.ColumnDefinitions>
<Grid Height='{TemplateBinding Height}' Width='{TemplateBinding Height}'>
<Rectangle x:Name='CheckBoxRectangle' Fill='""+ backcolor + @""' Opacity='0.3'/>
<Rectangle x:Name='CheckBoxRectangleOut' Stroke='"" + backcolor+@""' StrokeThickness='1' />
<Grid x:Name='CheckedMark' Width='"" + height + @""' Height='"" + height + @""' Visibility='Collapsed'>
<TextBlock Text='✓' FontSize='"" + (height - 3) + @""' Foreground='"" + select_color + @""' VerticalAlignment='Center' HorizontalAlignment='Center' />
</Grid>
</Grid>
<TextBlock Grid.Column='1' Text='"" + text + @""' FontSize='"" + fontsize + @""' Foreground='"" + fontcolor + @""' VerticalAlignment='Center' Margin='14,0,0,0'/>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property='IsChecked' Value='True'>
<Setter TargetName='CheckedMark' Property='Visibility' Value='Visible'></Setter>
<Setter TargetName='CheckBoxRectangle' Property='Fill' Value='""+backcolor+@""'></Setter>
<Setter TargetName='CheckBoxRectangle' Property='Opacity' Value='1'></Setter>
<Setter TargetName='CheckBoxRectangleOut' Property='Stroke' Value='Transparent'></Setter>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ResourceDictionary>"";
StringReader strreader = new StringReader(style);
XmlTextReader xmlreader = new XmlTextReader(strreader);
object obj = XamlReader.Load(xmlreader);
ResourceDictionary controlStyle = (ResourceDictionary)obj;
Resources.MergedDictionaries.Add(controlStyle);
var custom = Resources.MergedDictionaries[Get_ResourceCount()];
return custom[sKey] as Style;
} |