using CPF; using CPF.Animation; using CPF.Charts; using CPF.Controls; using CPF.Drawing; using CPF.Shapes; using CPF.Styling; using CPF.Svg; using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ConsoleApp1 { public class Window5 : Window { NotifyIcon notifyIcon = new NotifyIcon(); protected override void InitializeComponent() { notifyIcon.Icon = "res://ConsoleApp1/icon.png"; notifyIcon.Visible = true; notifyIcon.Text = "文字提示"; notifyIcon.MouseDown += NotifyIcon_MouseDown; notifyIcon.MouseUp += NotifyIcon_MouseUp; notifyIcon.Click += NotifyIcon_Click; notifyIcon.DoubleClick += NotifyIcon_DoubleClick; Icon = "res://ConsoleApp1/icon.png"; LoadStyleFile("res://ConsoleApp1/Stylesheet.css"); this.Styles.Add(new Style(new NameSelector("testBtn")) { //#testBtn .TextBlock Setters = { { nameof(Button.Width), 30 } } }); Title = "标题"; Width = 992; Height = 543; Background = null; CanResize = true; ContextMenu = new ContextMenu { Items = { new MenuItem { Header="增加一个选项", Commands = { {nameof(MenuItem.MouseDown),(s,e)=>{ ((s as MenuItem).OwnerContextMenu.Items[2] as MenuItem).Items.Add(new MenuItem{ Header="测试"}); } } } }, new MenuItem { Header="清除选项", Commands = { {nameof(MenuItem.MouseDown),(s,e)=>{ ((s as MenuItem).OwnerContextMenu.Items[2] as MenuItem).Items.Clear(); } } } }, new MenuItem { Header="选项2", Items= { new MenuItem { Header="选项1" }, } }, new Separator { }, new MenuItem { Header="选项3" } } }; notifyIcon.ContextMenu = ContextMenu; Children.Add(new WindowFrame(this, new Panel { UseLayoutRounding = true, Width = "100%", Height = "100%", Children = { new Panel { MarginLeft = 14, MarginTop = 4, Classes = "oneLine", IsGroup = true, Children = { new TextBlock { Classes = "label", MarginLeft = 7, Text = "标签", }, new ComboBox { Width = 158, MarginRight = 8, Items = { "231", "sdaf", "dfs", "fgsfs", "dfsgd", "dgds", "hdfs", "fgdgssa", "dgds", "ghdfs", "fgd", "ghdfs", "fggd", "sdfs", "fghdsa" } }, }, Height = 38, Width = 245, }, new Button { Commands = { { "Click", nameof(SetNotify), this, CommandParameter.EventSender, CommandParameter.EventArgs }, }, Classes = "primary", MarginLeft = 266, MarginTop = 12, Height = 30, Width = 90, Content = new StackPanel { Orientation = Orientation.Horizontal, Classes = "imgAndText", IsGroup = true, Children = { new Picture { Source = "res://ConsoleApp1/Resources/icon.png", Classes = "img", Height = 16, Width = 16, Stretch = Stretch.Uniform, }, new TextBlock { Foreground = "linear-gradient(0 0,100% 0,#000000 0,#FF0505 1)", MarginLeft = 5f, Classes = "text", Text = "notifyIcon", }, }, }, }, new Button { Commands = { { "Click", nameof(SwitchImage), this, CommandParameter.EventSender, CommandParameter.EventArgs }, }, Classes = "success", Height = 53, Width = 64, MarginLeft = 266, MarginTop = 57, Content = new StackPanel { Orientation = Orientation.Vertical, Classes = "imgAndText", IsGroup = true, Children = { new Picture { Source = "res://ConsoleApp1/Resources/主页.png", Classes = "img", Height = 16, Width = 16, Stretch = Stretch.Uniform, }, new TextBlock { MarginTop = 5f, Classes = "text", Text = "文字", }, }, }, }, new RadioButton { MarginLeft = 14, MarginTop = 83, Content = "RadioButton1", }, new RadioButton { MarginTop = 105, MarginLeft = 14, Content = "RadioButton2", }, new CheckBox { MarginLeft = 14, MarginTop = 128, Content = "CheckBox", }, new Panel { MarginLeft = 365, MarginTop = 14, IsGroup = true, Children = { new TextBox { MarginRight = 42.3f, MarginLeft = 2f, MarginTop = 0f, MarginBottom = 0f, Classes = "singleLine", }, new Border { Child = new TextBlock { Foreground = "#9093A2", MarginRight = 5f, MarginLeft = 5f, Text = ".com", }, Classes = "slotLeft", }, }, Classes = "textBox,groupPanel", Width = 134, Height = 27, }, new StackPanel { MarginLeft = 14, MarginTop = 51, IsGroup = true, Orientation= Orientation.Horizontal, Children = { new RadioButton { Content = "上海", GroupName="分组1", }, new RadioButton { Content = "北京", GroupName="分组1", }, new RadioButton { Content = "广州", GroupName="分组1", }, new RadioButton { Content = "RadioButton", }, }, Classes = "radioGroup", }, new Slider { MarginLeft = 14, MarginTop = 156, Height = 118, Width = 22, Orientation= Orientation.Vertical }, new ProgressBar { //IsIndeterminate = true, MarginLeft = 528, MarginTop = 17, Value = 10f, Height = 20, Width = 159, }, new NumericUpDown { Height = 28, Width = 63, MarginLeft = 379, MarginTop = 61, }, new DatePicker { MarginLeft = 499, MarginTop = 61, Height = 23f, Classes = "el-textbox", Width = 110f, }, new Panel { MarginLeft = 697, MarginTop = 17, Classes = "widget", IsGroup = true, Children = { new Panel { Classes = "widgetHead", Children = { new TextBlock { Classes = "label", MarginLeft = 7, Text = "标题", } }, MarginTop = 0, Height = 30, Width = "100%", }, new CheckBox { MarginLeft = 21, MarginTop = 47, Content = "CheckBox", }, new Button { Commands = { { "Click", nameof(CancelClosing), this, CommandParameter.EventSender, CommandParameter.EventArgs }, }, Height = 26, Width = 74, Content = "Cancel", }, }, Height = 186, Width = 276, }, new TabControl { Bindings = { { "SelectedIndex", "SelectedItem", FindPresenterByName("treeview"), BindingMode.OneWay, (TreeViewItem item)=>(item==null|| item.Tag==null)?0:int.Parse(item.Tag.ToString()) }, }, MarginLeft = 43, MarginTop = 156, TabStripPlacement = Dock.Left, Height = 271, Width = 453, Items = { new TabItem { Header = "选项1", FontSize = 15f, Content=new Panel { Children = { new TabControl { Items = { new TabItem { Content = new Panel { Children = { new Button { Commands = { { nameof(Button.Click), nameof(Click123), this, CommandParameter.EventSender, CommandParameter.EventArgs }, }, PresenterFor = this, Name = "testBtn", MarginLeft = 127, MarginTop = 56, Height = 41, Content = "Button12", }, }, Height = "100%", Width = "100%", }, Header = "TabItem", }, new TabItem { Content = new Panel { Children = { new SVG { Height = 100, IsAntiAlias = true, Width = 100, Stretch = Stretch.Uniform, Source="" } }, Height = "100%", Width = "100%", }, Header = new Panel { IsGroup = true, Children = { new TextBlock { MarginLeft = 34, Text = "sdaa文字", }, new SVG { Classes = "closeBtn", IsAntiAlias = true, Fill = "#939393", MarginRight = 5, Width = 13, Stretch = Stretch.Uniform, Source = "", }, new Picture { MarginLeft = 0, Source = "res://ConsoleApp1/Resources/icon.png", Classes = "img", Height = 16, Width = 16, Stretch = Stretch.Uniform, } }, Width = 120, }, }, new TabItem { Content = new Panel { Height = "100%", Width = "100%", }, Header = new StackPanel { Orientation = Orientation.Horizontal, Classes = "imgAndText", IsGroup = true, Children = { new Picture { Source = "res://ConsoleApp1/Resources/icon.png", Classes = "img", Height = 16, Width = 16, Stretch = Stretch.Uniform, }, new TextBlock { MarginLeft = 5f, Classes = "text", Text = "文字", }, }, }, }, new TabItem { Content = new Panel { Children = { }, Height = "100%", Width = "100%", }, Header = "TabItem", }, }, Height = 172, Width = 332, }, }, Height = "100%", Width = "100%", } }, new TabItem { Content = new Panel { Children = { new Label { MarginLeft = 31, MarginTop = 22, Text = "Label11", }, new CheckBox { MarginLeft = 221, MarginTop = 22, Content = "CheckBox", }, new Button { Commands = { { nameof(Button.Click), nameof(BtnClick), this, CommandParameter.EventSender, CommandParameter.EventArgs }, }, Content="弹窗", MarginLeft=59, MarginTop=64, Height=30, Width=100, }, }, Height = "100%", Width = "100%", }, Header = "TabItem", }, new TabItem { Content = new Panel { Children = { new Button { Height = 140, Width = 204, Content = new StackPanel { Height = 43, Width = 63, Orientation = Orientation.Vertical, Classes = "imgAndText", IsGroup = true, Children = { new Picture { Source = "res://ConsoleApp1/Resources/icon.png", Classes = "img", Height = 16, Width = 16, Stretch = Stretch.Uniform, }, new TextBlock { MarginTop = 5f, Classes = "text", Text = "文字231", }, }, }, } }, Height = "100%", Width = "100%", }, Header = "TabItem", }, new TabItem { Content = new Panel { Children = { new NativeElement { BackColor = "#FFC080", Height = 172, Width = 244, // #if !Net4//||!DesignMode // Content=new CPF.Mac.AppKit.NSButton{ Title="按钮",Frame=new CPF.Mac.CoreGraphics.CGRect(-20,0,100,50) } //#endif } }, Background="#0f0", Height = "100%", Width = "100%", }, Header = "TabItem", }, new TabItem { Content = new Panel { Children = { new Grid { MarginLeft = 65, MarginTop = 63, BorderStroke = "1,Solid", BorderFill = "#959595", PresenterFor = this, Name = "testGrid", IsGroup = true, ColumnDefinitions = { new ColumnDefinition { }, new ColumnDefinition { }, }, Children = { new GridSplitter { Height = "100%", MarginLeft = 0f, Attacheds = { { Grid.ColumnIndex, 1 }, }, }, new Border { BorderThickness = "1,2,1,1", BorderType = BorderType.BorderThickness, MarginLeft = 69, Height = 37, Width = 47, }, }, Height = 147, Width = 165, } }, Height = "100%", Width = "100%", }, Header = "TabItem", }, new TabItem { Content = new Panel { Children = { new Chart { GridShowMode = GridShowMode.Horizontal, GridFill = "#A5A5A5", YAxisScaleCount = 3, ChartFill = "#C7E5F6", CanScroll = true, IsAntiAlias = true, Height = 184, Width = 245, XAxis= { "1", "2", "3", "4", "5", "6", "7", "8", "9", "1", "2", "3", "4", "5", "6", "7", "8", "9", }, Data = { new ChartBarData { Name="test", Fill="#faf", Format="#'%'", Data = { 1, 2, 3 } }, new ChartBarData { Name="test1", Fill="#0af", Format="#'%'", ShowValueTip=true, Data = { 4, 5, 2 } }, new ChartLineData { Name="test2", LineFill="#a0f", Format="#'%'", LineType= LineTypes.Curve, BottomFill="#ff000033",//ShowValueTip=true, Data = { 4, 5, 2, 3, 4, 3, 4, 5, 2, 3, 4, 3, } }, new ChartLineData { Name="test2测试", LineFill="#0a0", BottomFill="#00000055", Data = { 3, 4, 5, 4, 3, 5, 3, 4, 5, 4, 3, 5, 5, 3, 4, 5, 4, 6, 5 } }, } }, }, Height = "100%", Width = "100%", }, Header = "TabItem", }, new TabItem { Content = new Panel { Children = { new PieChart { RingWidth = "40%", Height = 219, Width = 279, IsAntiAlias=true, Data = { new PieChartData { Name="test1", Fill="#ff000055", Value=0 }, new PieChartData { Name="test2", Fill="#00ff0055", Value=0 }, new PieChartData { Name="test3", Fill="#0000ff55", Value=0 }, new PieChartData { Name="test4", Fill="#00ffff55", Value=5 }, } }, }, Height = "100%", Width = "100%", }, Header = "TabItem", }, new TabItem { Content = new Panel { Height = "100%", Width = "100%", Children = { new Button { MarginLeft = 108, MarginTop = 95, Content="test", }, new TimePicker { } } }, Header = "TabItem", }, } }, new Panel { MarginLeft = 379, MarginTop = 101, Classes = "textBox,searchBox", IsGroup = true, Attacheds = { { AttachedExtenstions.IsEmpty, true, nameof(TextBox.Text), a=>a.GetChildren().First(b=>b is TextBox), BindingMode.OneWay, (string text)=>string.IsNullOrWhiteSpace(text) } }, Children = { new TextBox { PresenterFor = this, Name = nameof(textbox1), MarginTop = 3, MarginBottom = 3, MarginRight = 33, MarginLeft = 3, Classes = "singleLine", }, new Button { MarginTop = 0, MarginBottom = 0, MarginRight = 0, Width = 30, Content = new SVG { IsAntiAlias = true, Stretch= Stretch.Uniform, Width=16, Source = "", }, }, new TextBlock { MarginLeft = 8, Classes = "placeholder", Text = "placeholder", } }, Height = 30, Width = 200, }, new Panel { MarginLeft = 134, MarginTop = 116, Classes = "textBox", Attacheds = { { AttachedExtenstions.IsEmpty, true, nameof(TextBox.Text), a=>a.GetChildren().First(b=>b is TextBox), BindingMode.OneWay, (string text)=>string.IsNullOrWhiteSpace(text) } }, IsGroup = true, Children = { new TextBox { MarginBottom = 3, MarginRight = 3, MarginLeft = 3, MarginTop = 3, Classes = "singleLine", }, new TextBlock { MarginLeft = 8, Classes = "placeholder", Text = "placeholder", }, }, Height = 30, Width = 200, }, new SVG { MarginLeft = 882, MarginTop = 137, Height = 57, IsAntiAlias = true, Width = 55, Stretch = Stretch.Uniform, Source="" }, new TreeView { PresenterFor = this, Name = nameof(treeview), MarginLeft = 784, MarginTop = 202, Height = 209, Width = 189, Items = { new TreeViewNavItem { Header=new TextBlock { Foreground = "#9093A2", MarginRight = 5f, MarginLeft = 5f, Text = ".com", }, Items = { new TreeViewNavItem { Tag = "1", Header="123" } } }, new TreeViewNavItem { Header=new StackPanel { Orientation = Orientation.Horizontal, Classes = "imgAndText", IsGroup = true, Children = { new Picture { Source = "res://ConsoleApp1/Resources/arrow.png", Classes = "img", Height = 16, Width = 16, Stretch = Stretch.Uniform, }, new TextBlock { MarginLeft = 5f, Classes = "text", Text = "文字", }, }, }, Items = { new TreeViewNavItem { Header="123", Items = { new TreeViewNavItem { Tag = "2", Header="fgsfs" } } }, new TreeViewNavItem { Header="4533" } } }, new TreeViewNavItem { Header=new StackPanel { Orientation = Orientation.Horizontal, Classes = "imgAndText", IsGroup = true, Children = { new Picture { Source = "res://ConsoleApp1/Resources/icon.png", Classes = "img", Height = 16, Width = 16, Stretch = Stretch.Uniform, }, new TextBlock { MarginLeft = 5f, Classes = "text", Text = "文字1231", }, }, }, Items = { new TreeViewNavItem { Header="123" }, new TreeViewNavItem { Header="4533" } } }, } }, new Switch { PresenterFor = this, Name = "switch1", MarginLeft = 621, MarginTop = 128, Height = 21, Width = 39, IsChecked=true, }, new Panel { MarginLeft = 507, MarginTop = 202, IsGroup = true, Classes = "loginBox", Children = { new Panel { MarginTop = 64, Classes = "textBox", Attacheds = { { AttachedExtenstions.IsEmpty, true, nameof(TextBox.Text), a=>a.GetChildren().First(b=>b is TextBox), BindingMode.OneWay, (string text)=>string.IsNullOrWhiteSpace(text) } }, IsGroup = true, Children = { new TextBox { MarginBottom = 3, MarginRight = 3, MarginLeft = 3, MarginTop = 3, Classes = "singleLine", }, new TextBlock { MarginLeft = 10, Classes = "placeholder", Text = "用户名", }, }, Height = 36f, Width = 220f, }, new Panel { MarginTop = 118, Classes = "textBox", Attacheds = { { AttachedExtenstions.IsEmpty, true, nameof(TextBox.Text), a=>a.GetChildren().First(b=>b is TextBox), BindingMode.OneWay, (string text)=>string.IsNullOrWhiteSpace(text) } }, IsGroup = true, Children = { new TextBox { MarginLeft = 4, MarginRight = 5, PasswordChar = '#', MarginBottom = 2, MarginTop = 2, Classes = "singleLine", }, new TextBlock { MarginLeft = 10, Classes = "placeholder", Text = "密码", }, }, Height = 36, Width = 217, }, new CheckBox { MarginLeft = 112, MarginTop = 175, Content = "记住密码", }, new TextBlock { FontSize = 20f, MarginTop = 13, Text = "XX管理系统", }, }, Height = 209, Width = 274, }, new SVG { Commands = { { "DoubleClick", nameof(onClick), this, CommandParameter.EventSender, CommandParameter.EventArgs }, }, MarginLeft = 679, MarginTop = 89, Height = 136, IsAntiAlias = true, Width = 110, Stretch = Stretch.Uniform, Source="" }, new TextBox { Text = "2\r\n3", MarginLeft = 505, MarginTop = 138, Height = 64, Width = 98, }, new TimePicker { Height = 20, Width = 63, MarginLeft = 614, MarginTop = 63, }, } })); if (!DesignMode)//设计模式下不执行 { } } TextBox textbox1; private void NotifyIcon_DoubleClick(object sender, EventArgs e) { Console.WriteLine("NotifyIcon_DoubleClick"); } private void NotifyIcon_Click(object sender, EventArgs e) { Console.WriteLine("NotifyIcon_Click"); } private void NotifyIcon_MouseUp(object sender, EventArgs e) { Console.WriteLine("NotifyIcon_MouseUp"); } private void NotifyIcon_MouseDown(object sender, EventArgs e) { //Console.WriteLine("NotifyIcon_MouseDown"); //if (this.WindowState == WindowState.Normal) //{ // WindowState = WindowState.Minimized; //} //else if (WindowState == WindowState.Minimized) //{ // WindowState = WindowState.Normal; //} if (Visibility == Visibility.Collapsed) { Visibility = Visibility.Visible; } else { Visibility = Visibility.Collapsed; } } TreeView treeview; protected override void OnInitialized() { base.OnInitialized(); treeview = FindPresenterByName(nameof(treeview)); textbox1 = FindPresenterByName(nameof(textbox1)); textbox1.Focus(); } void btnClick(CpfObject obj, RoutedEventArgs eventArgs) { } void onClick(CpfObject obj, RoutedEventArgs eventArgs) { } void SetNotify(CpfObject obj, RoutedEventArgs eventArgs) { notifyIcon.Visible = !notifyIcon.Visible; } void SwitchImage(CpfObject obj, RoutedEventArgs eventArgs) { notifyIcon.Icon = "res://ConsoleApp1/Resources/arrow.png"; notifyIcon.Text = "test" + new Random().Next(0, 100); } bool cancel = false; void CancelClosing(CpfObject obj, RoutedEventArgs eventArgs) { cancel = !cancel; } protected override void OnClosing(ClosingEventArgs e) { notifyIcon.Dispose(); //e.Cancel = cancel; base.OnClosing(e); } async void BtnClick(CpfObject obj, RoutedEventArgs eventArgs) { //var f = new Window(); //f.Background = null; //f.Width = 300; //f.Height = 300; //f.CanResize = true; //f.Children.Add(new WindowFrame(f, new Button //{ // Content = "test", // Commands = // { // {nameof(Button.Click),(s,e)=>{ // MessageBox.Show("test"); // } } // } //})); //await f.ShowDialog(); await MessageBox.Show("Test", "标题", this); } void Click123(CpfObject obj, RoutedEventArgs eventArgs) { new LayerDialog { Width = 400, Height = 300, Content = new Button { Content = "测试" } }.ShowDialog(this); } } }