前言 QuestPDF 是一個開源 .NET 庫,用於生成 PDF 文檔。使用了C# Fluent API方式可簡化開發、減少錯誤並提高工作效率。利用它可以輕鬆生成 PDF 報告、發票、導出文件等。 項目介紹 QuestPDF 是一個革命性的開源 .NET 庫,它徹底改變了我們生成 PDF 文檔的方 ...
先看效果
我修改了ToggleButton的ControlTemplate,在ContentPresenter外面加了4個Border,控制4個Border的位置在ControlTemplate的左上、右上、左下、右下,選中時,觸發4個邊框的BorderThickness
<Setter Property="BorderThickness" TargetName="brdOut1" Value="2,2,0,0"/>
<Setter Property="BorderThickness" TargetName="brdOut2" Value="0 2 2 0"/>
<Setter Property="BorderThickness" TargetName="brdOut3" Value="2 0 0 2"/>
<Setter Property="BorderThickness" TargetName="brdOut4" Value="0 0 2 2"/>
<Style TargetType="{x:Type ToggleButton}"> <Setter Property="Background" Value="Transparent"/> <Setter Property="BorderBrush" Value="DarkGray"/> <Setter Property="BorderThickness" Value="1"/> <Setter Property="Padding" Value="0"/> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type ToggleButton}"> <Grid> <Border x:Name="brdOut1" BorderBrush="{StaticResource MaterialDesignGroupBorder}" Width="20" Height="20" HorizontalAlignment="Left" VerticalAlignment="Top"/> <Border x:Name="brdOut2" BorderBrush="{StaticResource MaterialDesignGroupBorder}" Width="20" Height="20" HorizontalAlignment="Right" VerticalAlignment="Top"/> <Border x:Name="brdOut3" BorderBrush="{StaticResource MaterialDesignGroupBorder}" Width="20" Height="20" HorizontalAlignment="Left" VerticalAlignment="Bottom"/> <Border x:Name="brdOut4" BorderBrush="{StaticResource MaterialDesignGroupBorder}" Width="20" Height="20" HorizontalAlignment="Right" VerticalAlignment="Bottom"/> <Border Margin="2" x:Name="border" BorderBrush="{TemplateBinding BorderBrush}" CornerRadius="0" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" SnapsToDevicePixels="True"> <ContentPresenter Grid.Row="1" x:Name="contentPresenter" ContentTemplate="{TemplateBinding ContentTemplate}" Content="{TemplateBinding Content}" ContentStringFormat="{TemplateBinding ContentStringFormat}" Focusable="False" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="{TemplateBinding Padding}" RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/> </Border> </Grid> <ControlTemplate.Triggers> <Trigger Property="IsChecked" Value="True"> <Setter Property="BorderThickness" TargetName="brdOut1" Value="2,2,0,0"/> <Setter Property="BorderThickness" TargetName="brdOut2" Value="0 2 2 0"/> <Setter Property="BorderThickness" TargetName="brdOut3" Value="2 0 0 2"/> <Setter Property="BorderThickness" TargetName="brdOut4" Value="0 0 2 2"/> </Trigger> </DataTrigger> </ControlTemplate.Triggers> </ControlTemplate> </Setter.Value> </Setter> </Style>
登錄界面
之前看過一個html的登錄界面效果挺好,就用wpf實現了一個
我是用的一個藍色的圓,移動了圓的位置,在登錄界面白色背景上形成了一個弧形劃分的效果;當然也可以用背景圖,但是我也沒找到類似的圖;這樣做還有個好處,可以根據系統主題,變換登錄界面弧形顏色。
右半部分的輸入框部分代碼我沒貼。
<Window Loaded="Window_Loaded" > <Grid> <Ellipse Grid.Row="1" x:Name="blueQ" Stroke="Black" Fill="#FF1C84EE"/> </Grid> </Window>
private void Window_Loaded(object sender, RoutedEventArgs e) { blueQ.Width = this.ActualHeight * 2; blueQ.Height = this.ActualHeight * 2; blueQ.Margin = new Thickness(-this.ActualHeight, -this.ActualHeight, 0, 0); }