Commit f445c84c authored by 潘栩锋's avatar 潘栩锋 🚴

1. 添加 主界面上方的报警条 可以右键拖动左右。 3秒自动保存位置。

2. 修复 进入多对象报警管理界面后,再按报警条,不能再让它再次打开多对象报警管理界面
3. 添加 为Button 添加  DrapMoveXBehavior 右键移动控件行为。 Button的上级应该为Grid
parent e1ca07f5
......@@ -3,7 +3,8 @@
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:MultiLayout"
xmlns:local="clr-namespace:MultiLayout" xmlns:b="http://schemas.microsoft.com/xaml/behaviors"
xmlns:flyctrl="clr-namespace:FLY.ControlLibrary;assembly=FLY.ControlLibrary"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800" Loaded="MainWindow_Loaded">
<Window.Resources>
......@@ -17,8 +18,11 @@
</Window.Resources>
<Grid d:DataContext="{StaticResource viewModel}">
<Frame Name="frame" NavigationUIVisibility="Hidden"/>
<Button Style="{StaticResource Styles.Button.Empty}" HorizontalAlignment="Right" VerticalAlignment="Top" Margin="0,0,50,0"
Visibility="{Binding IsErrMsgVisable,Converter={StaticResource visbilityconv}}" Click="btnErrMsgClick">
<Button x:Name="btnErrMsg" Style="{StaticResource Styles.Button.Empty}" HorizontalAlignment="Right" VerticalAlignment="Top" Margin="0,0,50,0"
Visibility="{Binding IsErrMsgVisable,Converter={StaticResource visbilityconv}}" Click="btnErrMsgClick" >
<b:Interaction.Behaviors>
<flyctrl:DrapMoveXBehavior Move="DrapMoveXBehavior_Move" />
</b:Interaction.Behaviors>
<Border Background="Red" CornerRadius="0, 0 10 10" Style="{StaticResource Styles.Shadow}">
<StackPanel Orientation="Horizontal">
<Grid Width="15"/>
......
......@@ -2,6 +2,7 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
......@@ -93,12 +94,59 @@ namespace MultiLayout
//启动Poll系统
//FObjBase.PollModule.Current.Start();
ErrMsgJsonDb jsonDb = new ErrMsgJsonDb();
if (jsonDb.Load()) {
var m = btnErrMsg.Margin;
m.Right = jsonDb.Right;
btnErrMsg.Margin = m;
}
}
private void btnErrMsgClick(object sender, RoutedEventArgs e)
{
manager.ErrMsgClick?.Invoke();
}
private void DrapMoveXBehavior_Move(object sender, EventArgs e)
{
ErrMsgJsonDb jsonDb = new ErrMsgJsonDb();
jsonDb.Right = (int)btnErrMsg.Margin.Right;
jsonDb.Save();
}
}
public class ErrMsgJsonDb
{
public int Right;
private string filePath = "errMsgPosition.json";
public bool Save()
{
try
{
string json = Newtonsoft.Json.JsonConvert.SerializeObject(this);
File.WriteAllText(filePath, json);
return true;
}
catch
{
return false;
}
}
public bool Load()
{
if (!File.Exists(filePath))
return false;
try
{
string json = File.ReadAllText(filePath);
Newtonsoft.Json.JsonConvert.PopulateObject(json, this);
return true;
}
catch {
return false;
}
}
}
public class WdMainVm:INotifyPropertyChanged
{
......
using Microsoft.Xaml.Behaviors;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Threading;
namespace FLY.ControlLibrary
{
/// <summary>
/// BUTTON 移动行为,附加行为。
/// </summary>
public class DrapMoveXBehavior : Behavior<UIElement>
{
//
// 摘要:
// 发生时 System.Windows.Controls.Button 时发生。
[Category("Behavior")]
public event EventHandler Move;
bool isDown = false;
Point downPoint;
/// <summary>
/// Move 事件滞后5秒触发
/// </summary>
public bool IsMoveEventDelayTrigger { get; set; } = true;
T GetParent<T>(DependencyObject dobj) where T : DependencyObject
{
//一直向上找,直到找到window
do
{
if (dobj is T)
{
break;
}
dobj = System.Windows.Media.VisualTreeHelper.GetParent(dobj);
} while (dobj != null);
return (T)dobj;
}
DispatcherTimer timer = new DispatcherTimer();
/// <summary>
///
/// </summary>
public DrapMoveXBehavior()
{
timer.Tick += Timer_Tick;
timer.Interval = TimeSpan.FromSeconds(3);
}
private void Timer_Tick(object sender, EventArgs e)
{
timer.Stop();
Move?.Invoke(AssociatedObject, null);
}
/// <summary>
///
/// </summary>
protected override void OnAttached()
{
base.OnAttached();
UIElement dobj = AssociatedObject;
dobj.MouseRightButtonDown += Dobj_MouseRightButtonDown;
dobj.MouseRightButtonUp += Dobj_MouseRightButtonUp;
dobj.MouseMove += Dobj_MouseMove;
dobj.MouseLeave += Dobj_MouseLeave;
parent = GetParent<Grid>(dobj);
}
private void Dobj_MouseLeave(object sender, MouseEventArgs e)
{
isDown = false;
}
private void Dobj_MouseMove(object sender, MouseEventArgs e)
{
//string json = Newtonsoft.Json.JsonConvert.SerializeObject(e);
if (!isDown)
return;
FrameworkElement fe = (FrameworkElement)AssociatedObject;
var downPoint = e.GetPosition(parent);
string json = Newtonsoft.Json.JsonConvert.SerializeObject(downPoint);
//移动
int x = (int)(downPoint.X - this.downPoint.X);
if (Math.Abs(x) < 2)
return;
this.downPoint = downPoint;
var m = fe.Margin;
if (fe.HorizontalAlignment == HorizontalAlignment.Center)
{
m.Right -= x * 2;
}
else if(fe.HorizontalAlignment == HorizontalAlignment.Right)
{
m.Right -= x;
}
else if(fe.HorizontalAlignment == HorizontalAlignment.Left)
{
m.Left += x;
}
fe.Margin = m;
if (IsMoveEventDelayTrigger)
{
timer.Start();
}
else
{
Move?.Invoke(AssociatedObject, null);
}
}
Grid parent;
private void Dobj_MouseRightButtonDown(object sender, MouseButtonEventArgs e)
{
downPoint = e.GetPosition(parent);
string json = Newtonsoft.Json.JsonConvert.SerializeObject(downPoint);
isDown = true;
}
private void Dobj_MouseRightButtonUp(object sender, MouseButtonEventArgs e)
{
isDown = false;
}
/// <summary>
///
/// </summary>
protected override void OnDetaching()
{
base.OnDetaching();
timer.Stop();
UIElement dobj = AssociatedObject;
dobj.MouseRightButtonDown -= Dobj_MouseRightButtonDown;
dobj.MouseRightButtonUp -= Dobj_MouseRightButtonUp;
dobj.MouseMove -= Dobj_MouseMove;
dobj.MouseLeave -= Dobj_MouseLeave;
}
}
}
......@@ -61,6 +61,7 @@
<Compile Include="COMMON.cs" />
<Compile Include="Converter\Item2IndexConverter.cs" />
<Compile Include="Converter\RatioConverter.cs" />
<Compile Include="DrapMoveXBehavior.cs" />
<Compile Include="GraphRange_coslight.cs" />
<Compile Include="GraphScan3.cs" />
<Compile Include="GraphScan4.xaml.cs">
......
......@@ -95,7 +95,14 @@ namespace FLY.Thick.Base.UI.OnInit
}
}
private void ErrMsg_OnClick() {
//打开管理页面
//当管理页面已经打开,不能再次执行
if (FlyLayoutManager.NavigationService.Content is PgErrorsTable) {
return;
}
var p = container.Resolve<PgErrorsTable>();
FlyLayoutManager.NavigationService.Navigate(p);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment