既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,涵盖了95%以上大数据知识点,真正体系化!
由于文件比较多,这里只是将部分目录截图出来,全套包含大厂面经、学习笔记、源码讲义、实战项目、大纲路线、讲解视频,并且后续会持续更新
参考链接:WPF一次性开启两个窗口 - 夜落璇玑 - 博客园 (cnblogs.com)")
2.实现点击窗口任意位置拖动
1、注册3个事件如下:
// xaml里
<Window PreviewMouseLeftButtonDown="Window_PreviewMouseLeftButtonDown"
PreviewMouseMove="Window_PreviewMouseMove"
PreviewMouseLeftButtonUp="Window_PreviewMouseLeftButtonUp"/>
//cs里
public partial class subWindow : Window
{
//定义2个变量记录信息
Point _pressedPosition;
bool _isDragMoved = false;
public subWindow()
{
InitializeComponent();
}
//记录鼠标按下位置
void Window_PreviewMouseLeftButtonDown(object sender,
System.Windows.Input.MouseButtonEventArgs e)
{
_pressedPosition = e.GetPosition(this);
}
//鼠标移动触发拖动
void Window_PreviewMouseMove(object sender, System.Windows.Input.MouseEventArgs e)
{
if (Mouse.LeftButton == MouseButtonState.Pressed && _pressedPosition != e.GetPosition(this))
{
_isDragMoved = true;
DragMove();
}
}
//鼠标弹起屏蔽消息
void Window_PreviewMouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
if (_isDragMoved)
{
_isDragMoved = false;
e.Handled = true;
}
}
}
参考链接:c# wpf 实现窗口任意区域点击拖动_wpf 拖动窗体-CSDN博客
3.实现一个透明、无边框、鼠标穿透的WPF窗体
参考链接:Simple WPF:实现一个透明、无边框、鼠标穿透的WPF窗体 - 知乎 (zhihu.com)")
//设置 AllowsTransparency="True" WindowStyle="None" Background="Transparent"
<Window x:Class="WpfApp1.subWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
PreviewMouseLeftButtonDown="Window_PreviewMouseLeftButtonDown"
PreviewMouseMove="Window_PreviewMouseMove"
PreviewMouseLeftButtonUp="Window_PreviewMouseLeftButtonUp"
xmlns:local="clr-namespace:WpfApp1"
mc:Ignorable="d"
Title="subWindow" Height="500" Width="700" AllowsTransparency="True" WindowStyle="None" Background="Transparent">
4.去除标题栏
//设置 WindowStyle ="None"
<Window x:Class="NonFrameWindow.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:NonFrameWindow"
mc:Ignorable="d"
WindowStyle ="None" ResizeMode="CanMinimize"
Title="MainWindow" Height="450" Width="800">
5.按钮渐变色 鼠标悬停时按钮不变色 控件重叠
<Window.Resources>
//设置grid的背景色
<Style TargetType="Grid" x:Key="ggrid">
<Setter Property="Background" Value="#F5F7F6F6"></Setter>
</Style>
<!--按钮渐变色-->
<LinearGradientBrush x:Key="Brush2" StartPoint="0,0" EndPoint="0,1">
<LinearGradientBrush.GradientStops>
<GradientStop Offset="0" Color="#FF03A795" />
<GradientStop Offset="1" Color="#FF03786B" />
</LinearGradientBrush.GradientStops>
</LinearGradientBrush>
<LinearGradientBrush x:Key="Brush3" StartPoint="0,0" EndPoint="0,1">
<LinearGradientBrush.GradientStops>
<GradientStop Offset="0" Color="#FF03A795" />
<GradientStop Offset="1" Color="#FF03786B" />
</LinearGradientBrush.GradientStops>
</LinearGradientBrush>
<!--button鼠标悬停时不变色-->
<Style x:Key="ButtonStyle" TargetType="{x:Type Button}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Button}">
<Border Background="{TemplateBinding Background}">
<ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center"/>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" Value="{x:Null}"/>
</Trigger>
</Style.Triggers>
</Style>
</Window.Resources>
//调用
<Button Width="130" Height="50" Margin="5" Background="Transparent" BorderThickness="0,0,0,0" Style="{DynamicResource ButtonStyle}">
<Canvas>
<Border BorderThickness="2" Canvas.Left="-17" Canvas.Top="-14" Background="{StaticResource Brush3}" CornerRadius="4" Height="35" Width="80">
//border的渐变色
<Border.BorderBrush>
<RadialGradientBrush>
<GradientStop Color="Black"/>
<GradientStop Color="#FFCCCBCC" Offset="1"/>
</RadialGradientBrush>
</Border.BorderBrush>
<Label Content="123" FontSize="14" Margin="11,1,15,0" />
</Border>
<Border BorderThickness="2" Canvas.Left="-50" Canvas.Top="-17" Background="{StaticResource Brush2}" CornerRadius="18" Height="42" MinWidth="25">
<Border.BorderBrush>
<RadialGradientBrush>
<GradientStop Color="Black"/>
<GradientStop Color="#FFCCCBCC" Offset="1"/>
</RadialGradientBrush>
</Border.BorderBrush>
<Label Content="12" FontSize="14" HorizontalContentAlignment="Center" Margin="0,4,0,0" MinWidth="40"></Label>
</Border>
</Canvas>
</Button>
6. grid 分割线
<Grid.RowDefinitions>
<RowDefinition Height="9*"/>
<RowDefinition Height="9*"/>
<RowDefinition Height="12*"/>
<RowDefinition Height="12*"/>
<RowDefinition Height="24*"/>
<RowDefinition Height="3*"/>
</Grid.RowDefinitions>
<Rectangle Stroke="#FF6F6D6D" Grid.Row="1"/>
<Rectangle Stroke="#FF6F6D6D" Grid.Row="2"/>
<Rectangle Stroke="#FF6F6D6D" Grid.Row="3"/>
<Rectangle Stroke="#FF6F6D6D" Grid.Row="4"/>
<Rectangle Stroke="#FF6F6D6D" Grid.Row="5"/>
7. textblock 样式(渐变色 )
<TextBlock VerticalAlignment="Bottom" HorizontalAlignment="Left" FontSize="25" FontWeight="Black" Cursor="AppStarting" Height="30">
<TextBlock.Style>
<Style TargetType="{x:Type TextBlock}">
<Setter Property="Foreground">
<Setter.Value>
<LinearGradientBrush StartPoint="0.5,0" EndPoint="0.5,0.5">
<GradientStop Color="#FF87E1FF" Offset="0.0" />
<GradientStop Color="#FF009FFF" Offset="0.5" />
</LinearGradientBrush>
</Setter.Value>
</Setter>
</Style>
</TextBlock.Style><Run Text="抢答器专家"/>
</TextBlock>
//设置字体颜色
<TextBlock Foreground="#FF03786B">加分</TextBlock>
8.textbox 样式(圆角)
<TextBox VerticalAlignment="Center" HorizontalAlignment="Center" Height="30" Width="60" >
<TextBox.Resources>
<Style TargetType="{x:Type Border}">
<Setter Property="CornerRadius" Value="2"/>
<Setter Property="BorderBrush" Value="#c1d0dc"/>
</Style>
</TextBox.Resources>
</TextBox>
9.button
//设置圆角
<Button.Resources>
<Style TargetType="{x:Type Border}">
<Setter Property="CornerRadius" Value="3"></Setter>
</Style>
</Button.Resources>
//设置阴影
<Button.Effect>
<DropShadowEffect BlurRadius="20" ShadowDepth="0" Color="#DADADA" Opacity="0.2"/>
</Button.Effect>
10.ComboBox
xaml:
<ComboBox Width="80" SelectionChanged="ComboBox_SelectionChanged">
<ComboBoxItem IsSelected="True">0</ComboBoxItem>
<ComboBoxItem>5</ComboBoxItem>
<ComboBoxItem>10</ComboBoxItem>
<ComboBoxItem>20</ComboBoxItem>
</ComboBox>
//允许编辑 设置IsEditable="True",即前面变成文本框形式
<ComboBox x:Name="AddScoreCombox" Width="80" IsEditable="True">
<ComboBoxItem>0</ComboBoxItem>
<ComboBoxItem>10</ComboBoxItem>
<ComboBoxItem>11</ComboBoxItem>
<ComboBoxItem IsSelected="True">19</ComboBoxItem>
</ComboBox>
cs:
private void ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
int count = Convert.ToInt32(combobox.SelectedValue.ToString().Replace("System.Windows.Controls.ComboBoxItem: ", ""));
SubWindow subWindow = SubWindow.pwindow;
subWindow.Close();
SubWindow.hcount = count;
SubWindow subWindow2 = new SubWindow();
subWindow2.Show();
}
//动态生成Items
for(int i = 1; i <= SubWindow.count; i++)
{
combobox.Items.Add(i.ToString());
}
11.在子窗口控制主窗口动态生成控件时,会出现两个相同的窗口
解决办法:
在主窗口里
public static SubWindow pwindow = null;
public SubWindow()
{
InitializeComponent();
pwindow = this; //将当前窗口给pwindow,方便在setting里使用
}
在子窗口里,
SubWindow subWindow = SubWindow.pwindow;
subWindow.Close(); //关闭上一个窗口
SubWindow.hcount = count;
SubWindow subWindow2 = new SubWindow();
subWindow2.Show();
12.RadioButton
<RadioButton GroupName="zu" Margin="20,10,0,10" Grid.Row="0" Content="12" Click="RadioButton_Click"> </RadioButton>
<RadioButton IsChecked="True" GroupName="zu" Margin="20,10,0,10" Grid.Row="1" Content="34" Click="RadioButton_Click"></RadioButton>
private void RadioButton_Click(object sender, RoutedEventArgs e)
{
//获取radiobutton的值
RadioButton radioButton = sender as RadioButton;
radiobuttoncContent = radioButton.Content.ToString();
if (radioButton.IsChecked == true)
{
SubWindow subWindow = SubWindow.pwindow;
subWindow.Close();
SubWindow subWindow2 = new SubWindow();
subWindow2.Show();
}
}
13.slider
<WrapPanel Margin="20,70,0,0">
<TextBlock FontSize="14" LineHeight="12" Foreground="#333333">调整</TextBlock>
<Slider x:Name = "slider2" Width="90" Minimum = "0" Maximum = "3" ValueChanged = "slider1_ValueChanged" Margin = "23,0,0,0"></Slider>
<TextBox x:Name="textbox1" Text="{Binding Textbox1}" Width="25" Height="25" Margin="5,-3,0,0" VerticalContentAlignment="Center" HorizontalContentAlignment="Center"></TextBox>
</WrapPanel>
public static int buttonSize = 0;
private void slider1_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
{
string val = Convert.ToInt32(e.NewValue).ToString();
//string msg = String.Format("Current value: {0}", val);
this.textbox1.Text = val;
buttonSize =Convert.ToInt32(val);
SubWindow subWindow = SubWindow.pwindow;
subWindow.Close();
SubWindow subWindow2 = new SubWindow();
subWindow2.Show();
}
14.动态生成控件
private void CreateCanvas3()
{
LinearGradientBrush brush3 = (LinearGradientBrush)this.FindResource("Brush3");
LinearGradientBrush brush2 = (LinearGradientBrush)this.FindResource("Brush2");
Canvas canvas = new Canvas()
{
Margin = new Thickness(30 + buttonsize * 3 + Llength, 40 + buttonsize * 4 + hlength * 2, 90 + buttonsize * 3 + Llength, 40 + buttonsize * 3 + hlength * 2)
};
//成绩
Border border = new Border()
{
BorderThickness = new Thickness(2),
BorderBrush = System.Windows.Media.Brushes.WhiteSmoke,
Background = brush3,
CornerRadius = new CornerRadius(4),
Margin = new Thickness(30 + buttonsize * 6, 20 + buttonsize * 6, 2 + buttonsize * 6, 0+buttonsize * 6),
Height = 35 + buttonsize * 4,
Width = 80 + buttonsize * 5
};
Label label = new Label()
{
Content = "123",
FontSize = 14 + buttonsize * 2,
Margin = new Thickness(15, 1, 15, 0),
HorizontalContentAlignment = HorizontalAlignment.Center,
VerticalContentAlignment = VerticalAlignment.Center,
};
//名称
Border border2 = new Border()
{
BorderThickness = new Thickness(2,0,2,2),
BorderBrush = System.Windows.Media.Brushes.WhiteSmoke,
Background = brush3,
CornerRadius = new CornerRadius(0,0,4,4),
Margin = new Thickness(30 + buttonsize * 6, 53 + buttonsize * 6, 0 + buttonsize * 6, 0 + buttonsize * 6),
Height = 35 + buttonsize * 4,
Width = 80 + buttonsize * 5
};
Label label2 = new Label()
{
Content = "456",
FontSize = 14 + buttonsize * 2,
Margin = new Thickness(18, 1, 15, 0),
HorizontalContentAlignment = HorizontalAlignment.Center,
VerticalContentAlignment = VerticalAlignment.Center,
};
border.Child = label;
border2.Child = label2;
//组号
Border border1 = new Border()
{
BorderThickness = new Thickness(2),
BorderBrush = System.Windows.Media.Brushes.WhiteSmoke,
Background = brush2,
CornerRadius = new CornerRadius(50),
Margin = new Thickness(15 + buttonsize * 4, 17 + buttonsize * 4, 0, 0),
Height = 42 + buttonsize * 2,
Width = 40 + buttonsize * 2
![img](https://img-blog.csdnimg.cn/img_convert/51c0f9662b57ca752c92e1355a7c318e.png)
![img](https://img-blog.csdnimg.cn/img_convert/72864a16a4ada86dd996fbb90df0cfb8.png)
![img](https://img-blog.csdnimg.cn/img_convert/1189b89a03e6f76f77fe85b16792bb3e.png)
**既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,涵盖了95%以上大数据知识点,真正体系化!**
**由于文件比较多,这里只是将部分目录截图出来,全套包含大厂面经、学习笔记、源码讲义、实战项目、大纲路线、讲解视频,并且后续会持续更新**
**[需要这份系统化资料的朋友,可以戳这里获取](https://bbs.csdn.net/topics/618545628)**
(15 + buttonsize * 4, 17 + buttonsize * 4, 0, 0),
Height = 42 + buttonsize * 2,
Width = 40 + buttonsize * 2
[外链图片转存中...(img-tB2Z34q2-1715797743046)]
[外链图片转存中...(img-qJmBougT-1715797743047)]
[外链图片转存中...(img-FKBb7zAW-1715797743047)]
**既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,涵盖了95%以上大数据知识点,真正体系化!**
**由于文件比较多,这里只是将部分目录截图出来,全套包含大厂面经、学习笔记、源码讲义、实战项目、大纲路线、讲解视频,并且后续会持续更新**
**[需要这份系统化资料的朋友,可以戳这里获取](https://bbs.csdn.net/topics/618545628)**