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

1. 整理 界面模块

parent 5aee9945
using Newtonsoft.Json.Linq;
using System;
using System.CodeDom;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static Misc.BindingOperations;
namespace Misc
{
......@@ -51,7 +53,45 @@ namespace Misc
{
return GetValue<T>(key, default(T));
}
public object GetValue(Type type, string key, object defaultValue)
{
var cell = cells.Find(c => c.Key == key);
if (cell == null)
{
cell = new KeyValueCell() { Key = key, Value = defaultValue };
cell.IsConverted = true;
cells.Add(cell);
return cell.Value;
}
else
{
if (cell.IsConverted)
return cell.Value;
else
{
cell.ToValue(type);
return cell.Value;
}
}
}
public object GetValue(Type type, string key)
{
var cell = cells.Find(c => c.Key == key);
if (cell == null)
{
return null;
}
else
{
if (cell.IsConverted)
return cell.Value;
else
{
cell.ToValue(type);
return cell.Value;
}
}
}
/// <summary>
/// 获取值,如果没有返回默认值
......@@ -84,6 +124,41 @@ namespace Misc
}
}
/// <summary>
/// 双向绑定
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="src"></param>
/// <param name="target"></param>
/// <param name="propertyName"></param>
/// <param name="defaultValue"></param>
public void SetBinding<T>(INotifyPropertyChanged target, string propertyName, T defaultValue)
{
Type type_s = target.GetType();
System.Reflection.PropertyInfo pi_t = type_s.GetProperty(propertyName);
if (pi_t == null)
return;
object obj = GetValue<T>(propertyName, defaultValue);
pi_t.SetValue(target, obj);
target.PropertyChanged += (s, e) =>
{
if (e.PropertyName == propertyName)
{
object o = pi_t.GetValue(target);
SetValue(propertyName, o);
}
};
ValueChanged += (s, e) =>
{
if (e.Key == propertyName) {
object o = GetValue<T>(propertyName, defaultValue);
pi_t.SetValue(target, o);
}
};
}
private string path;
public event UiParamDictionaryValueChangedHandler ValueChanged;
......@@ -108,12 +183,21 @@ namespace Misc
}
}
public void Save()
{
foreach (var cell in cells)
{
try
{
foreach (var cell in cells)
cell.ToToken();
}
catch (Exception e)
{
}
}
try
{
string json = Newtonsoft.Json.JsonConvert.SerializeObject(cells, Newtonsoft.Json.Formatting.Indented);
File.WriteAllText(path, json);
}
......@@ -166,6 +250,13 @@ namespace Misc
return;
Value = Token.ToObject<T>();
}
public void ToValue(Type type)
{
IsConverted = true;
if (Token == null)
return;
Value = Token.ToObject(type);
}
public void ToToken()
{
Token = JToken.FromObject(Value);
......
......@@ -129,6 +129,57 @@ namespace Misc
}break;
}
}
public static void SetBinding(INotifyPropertyChanged src, string srcPropertyName, ParamDictionary target, string targetPropertyName, BindingMode mode)
{
Type type_s = src.GetType();
System.Reflection.PropertyInfo pi_s = type_s.GetProperty(srcPropertyName);
if (pi_s == null)
return;
switch (mode)
{
case BindingMode.OneWay://src->target
{
object obj = pi_s.GetValue(src, null);
target.SetValue(targetPropertyName, obj);
src.PropertyChanged += (s, e) =>
{
if (e.PropertyName == srcPropertyName)
{
object o = pi_s.GetValue(src, null);
target.SetValue(targetPropertyName, obj);
}
};
}
break;
case BindingMode.TwoWay://src->target then target->src
{
object obj = pi_s.GetValue(src, null);
target.SetValue(targetPropertyName, obj);
src.PropertyChanged += (s, e) =>
{
if (e.PropertyName == srcPropertyName)
{
object o = pi_s.GetValue(s, null);
target.SetValue(targetPropertyName, obj);
}
};
target.ValueChanged += (s, e) =>
{
if (e.Key == targetPropertyName)
{
object o = target.GetValue(pi_s.PropertyType, targetPropertyName);
pi_s.SetValue(src, o, null);
}
};
}
break;
}
}
}
}
......@@ -92,28 +92,11 @@ namespace FLY.Thick.Base.UI.CustomSection
{
this.paramDictionary = paramDictionary;
this.lCUS1 = lCUS1;
WarningTipPath = this.paramDictionary.GetValue(ParamDistItemKeys.WarningTipPath, "");
var v = this.paramDictionary.GetValue<int>(ParamDistItemKeys.WarningDurationSec);
WarningDurationSec = this.paramDictionary.GetValue(ParamDistItemKeys.WarningDurationSec, 5);
EnableScanErrBigTip = this.paramDictionary.GetValue(ParamDistItemKeys.EnableScanErrBigTip, false);
LCUS1_PortName = this.paramDictionary.GetValue(ParamDistItemKeys.LCUS1_PortName, "COM1");
EnableLCUS1 = this.paramDictionary.GetValue(ParamDistItemKeys.EnableLCUS1, false);
this.PropertyChanged += (s, e) =>
{
if (e.PropertyName == "WarningTipPath")
this.paramDictionary.SetValue(ParamDistItemKeys.WarningTipPath, WarningTipPath);
else if (e.PropertyName == "WarningDurationSec")
this.paramDictionary.SetValue(ParamDistItemKeys.WarningDurationSec, WarningDurationSec);
else if (e.PropertyName == "EnableScanErrBigTip")
this.paramDictionary.SetValue(ParamDistItemKeys.EnableScanErrBigTip, EnableScanErrBigTip);
else if (e.PropertyName == "LCUS1_PortName")
this.paramDictionary.SetValue(ParamDistItemKeys.LCUS1_PortName, LCUS1_PortName);
else if (e.PropertyName == "EnableLCUS1")
this.paramDictionary.SetValue(ParamDistItemKeys.EnableLCUS1, EnableLCUS1);
};
paramDictionary.SetBinding(this, "WarningTipPath", "");
paramDictionary.SetBinding(this, "WarningDurationSec", 5);
paramDictionary.SetBinding(this, "EnableScanErrBigTip", false);
paramDictionary.SetBinding(this, "LCUS1_PortName", "COM1");
paramDictionary.SetBinding(this, "EnableLCUS1", false);
}
private void Play()
......
......@@ -41,7 +41,6 @@ namespace FLY.Thick.Base.UI.CustomSection
public bool HaveOSK_mouse { get; set; }
ParamDictionary paramDictionary;
public UcSectionOskVm()
{
......@@ -49,16 +48,8 @@ namespace FLY.Thick.Base.UI.CustomSection
public void Init(ParamDictionary paramDictionary)
{
this.paramDictionary = paramDictionary;
HaveOSK = paramDictionary.GetValue(ParamDistItemKeys.HaveOSK, true);
HaveOSK_mouse = paramDictionary.GetValue(ParamDistItemKeys.HaveOSK_mouse, false);
this.PropertyChanged += (s, e) =>
{
if (e.PropertyName == ParamDistItemKeys.HaveOSK)
this.paramDictionary.SetValue(ParamDistItemKeys.HaveOSK, HaveOSK);
else if (e.PropertyName == ParamDistItemKeys.HaveOSK_mouse)
this.paramDictionary.SetValue(ParamDistItemKeys.HaveOSK_mouse, HaveOSK_mouse);
};
paramDictionary.SetBinding(this, "HaveOSK", false);
paramDictionary.SetBinding(this, "HaveOSK_mouse", false);
}
}
......
......@@ -203,6 +203,9 @@
<Compile Include="PgPwManager.xaml.cs">
<DependentUpon>PgPwManager.xaml</DependentUpon>
</Compile>
<Compile Include="UiModule\DynAreaFilmWidth.xaml.cs">
<DependentUpon>DynAreaFilmWidth.xaml</DependentUpon>
</Compile>
<Compile Include="UiModule\DynAreaIO.xaml.cs">
<DependentUpon>DynAreaIO.xaml</DependentUpon>
</Compile>
......@@ -371,6 +374,10 @@
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Page Include="UiModule\DynAreaFilmWidth.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Page Include="UiModule\DynAreaIO.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
......
......@@ -21,7 +21,7 @@
<Grid >
<Grid.RowDefinitions>
<RowDefinition Height="auto" />
<RowDefinition Height="496*" />
<RowDefinition />
</Grid.RowDefinitions>
<Grid Background="{StaticResource Background_Title}" >
<Grid.ColumnDefinitions>
......
......@@ -24,22 +24,27 @@
<RowDefinition Height="auto" />
<RowDefinition />
</Grid.RowDefinitions>
<Grid Name="grid_null"/>
<StackPanel Orientation="Horizontal" Background="{StaticResource Background_Title}">
<Button Style="{StaticResource ButtonStyle_back2}" Command="BrowseBack"/>
<Grid Background="{StaticResource Background_Title}" >
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition Width="auto"/>
</Grid.ColumnDefinitions>
<StackPanel Orientation="Horizontal" >
<Button Style="{StaticResource ButtonStyle_back2}" Command="BrowseBack" />
<TextBlock Style="{StaticResource TextBlockStyle_Title}" Text="机架信息"/>
</StackPanel>
<local:CtMicroGage Grid.Column="1" x:Name="mircoGage" Background="Transparent" VerticalAlignment="Bottom"/>
</Grid>
<Grid Grid.Row="1" Margin="0,5,0,5">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="auto" />
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<Button Click="button_start_Click" >
<TextBlock Text="录制" >
<TextBlock >
<TextBlock.Style>
<Style TargetType="TextBlock" BasedOn="{StaticResource TextStyle_paramSection}" >
<Setter Property="Text" Value="录制"/>
<Style.Triggers>
<DataTrigger Binding="{Binding IsRunning}" Value="True">
<Setter Property="Text" Value="停止"/>
......
......@@ -40,6 +40,7 @@ namespace FLY.Thick.Base.UI
this.getSample = getSample;
this.borderSearch = borderSearch;
this.container = container;
container.BuildUp(mircoGage);
}
private void Page_Loaded(object sender, RoutedEventArgs e1)
{
......@@ -99,6 +100,9 @@ namespace FLY.Thick.Base.UI
{
update();
};
DataBindAll();
update();
}
void InitializeComponent2()
......
......@@ -22,8 +22,7 @@
<Grid >
<Grid.RowDefinitions>
<RowDefinition Height="auto" />
<RowDefinition Height="496*" />
<RowDefinition Height="auto" />
<RowDefinition />
</Grid.RowDefinitions>
<StackPanel Orientation="Horizontal" Background="{StaticResource Brush_theme_bar}">
<Button Style="{StaticResource ButtonStyle_back2}" Command="BrowseBack"/>
......
<UserControl x:Class="FLY.Thick.Base.UI.UiModule.DynAreaFilmWidth"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
d:DesignWidth="250"
mc:Ignorable="d" >
<UserControl.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/FLY.ControlLibrary;component/Themes/Dictionary_MyStyle.xaml"/>
<ResourceDictionary Source="pack://application:,,,/FLY.Thick.Base.UI;component/Converter/Dictionary_MyConv.xaml"/>
</ResourceDictionary.MergedDictionaries>
<Style TargetType="TextBlock" x:Key="TextBlockStyle_ItemHeader">
<Setter Property="FontWeight" Value="Bold"/>
<Setter Property="FontFamily" Value="YouYuan"/>
<Setter Property="FontSize" Value="12"/>
<Setter Property="HorizontalAlignment" Value="Left"/>
<Setter Property="Foreground" Value="#FF3B3B3B"/>
<Setter Property="Margin" Value="5,0"/>
</Style>
</ResourceDictionary>
</UserControl.Resources>
<Grid>
<Button Click="Border_Width_Click" Width="250" Style="{StaticResource ButtonStyle_empty}" Visibility="{Binding Enable,Converter={StaticResource visbilityconv},ConverterParameter=Collapsed}">
<Border Style="{StaticResource BorderStyle_module}" >
<StackPanel Margin="2">
<StackPanel Orientation="Horizontal" Margin="2">
<StackPanel Orientation="Horizontal" >
<TextBlock Text="横向宽度" FontSize="12" FontWeight="Bold" FontFamily="YouYuan" TextAlignment="Center" HorizontalAlignment="Center" Foreground="#FF3B3B3B" />
<StackPanel Orientation="Horizontal" Margin="5,0">
<TextBlock Text="{Binding Width, StringFormat={}{0:F0}}" FontSize="20" FontFamily="Microsoft Sans Serif" TextAlignment="Center" HorizontalAlignment="Center" Foreground="{StaticResource Color_theme_activity}" />
<TextBlock Style="{StaticResource ResourceKey=TextBlockStyle_FieldContent_mm}" Text="mm" FontSize="12" />
</StackPanel>
</StackPanel>
<StackPanel Orientation="Horizontal">
<TextBlock Text="纵向速度" FontSize="12" FontWeight="Bold" FontFamily="YouYuan" TextAlignment="Center" HorizontalAlignment="Center" Foreground="#FF3B3B3B" />
<StackPanel Orientation="Horizontal" Margin="5,0">
<TextBlock Text="{Binding FilmVelocity, StringFormat={}{0:F1}}" FontSize="24" FontFamily="Microsoft Sans Serif" TextAlignment="Center" HorizontalAlignment="Center" Foreground="{StaticResource Color_theme_activity}" />
<TextBlock Style="{StaticResource ResourceKey=TextBlockStyle_FieldContent_mm}" Text="m/min" FontSize="12" />
</StackPanel>
</StackPanel>
</StackPanel>
<StackPanel Orientation="Horizontal" Margin="2">
<StackPanel Orientation="Horizontal">
<TextBlock Text="纵向位置" FontSize="12" FontWeight="Bold" FontFamily="YouYuan" TextAlignment="Center" HorizontalAlignment="Center" Foreground="#FF3B3B3B" />
<StackPanel Orientation="Horizontal" Margin="5,0">
<TextBlock Text="{Binding FilmPosition, StringFormat={}{0:F2}}" FontSize="24" FontFamily="Microsoft Sans Serif" TextAlignment="Center" HorizontalAlignment="Center" Foreground="{StaticResource Color_theme_activity}" />
<TextBlock Style="{StaticResource ResourceKey=TextBlockStyle_FieldContent_mm}" Text="m" FontSize="12" />
</StackPanel>
</StackPanel>
</StackPanel>
</StackPanel>
</Border>
</Button>
</Grid>
</UserControl>
\ No newline at end of file
using FLY.Thick.Base.Common;
using MultiLayout.UiModule;
using System.Windows;
using System.Windows.Controls;
using Unity;
namespace FLY.Thick.Base.UI.UiModule
{
/// <summary>
/// DynAreaFilmWidth.xaml 的交互逻辑
/// </summary>
public partial class DynAreaFilmWidth : UserControl
{
//TDGage gage;
private IUnityContainer container;
private DynArea dynArea;
public DynAreaFilmWidth()
{
InitializeComponent();
}
[InjectionMethod]
public void Init(
IUnityContainer container,
FLY.Thick.Base.IService.IDynAreaService dynAreaService
)
{
this.container = container;
dynArea = dynAreaService.DynArea;
this.DataContext = dynArea;
}
private void Border_Width_Click(object sender, RoutedEventArgs e)
{
PgBorderSearch p = new PgBorderSearch();
container.BuildUp(p);
MultiLayout.FlyLayoutManager.NavigationService.Navigate(p);
}
}
public class UiModule2_DynAreaFilmWidth : IUiModule2
{
/// <summary>
/// 控件标题
/// 它的值取决于culture
/// </summary>
public string Title => "边界查找";
public ComponentType Type => ComponentType.DynArea;
public bool IsUnique => true;
/// <summary>
/// 控件
/// 创建时,需要给它唯一ID,让加载自己的数据
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
public FrameworkElement GetComponent(int id, IUnityContainer container)
{
DynAreaFilmWidth graph = new DynAreaFilmWidth();
container.BuildUp(graph);
return graph;
}
/// <summary>
/// 控件缩略图,用于编辑界面时,大致看看
/// 创建时,需要给它唯一ID,让加载自己的数据
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
public FrameworkElement GetThumbnail()
{
return new System.Windows.Controls.Grid();
}
/// <summary>
/// 给出全部控件ID, 控件自行删除没有的参数
/// </summary>
/// <param name="IDs"></param>
public void MatchParam(int[] IDs)
{
}
}
}
......@@ -19,20 +19,6 @@ namespace FLY.Thick.Base.Client
[JsonObject(MemberSerialization.OptIn)]
public class GetSampleServiceClient : FObjServiceClient, IGetSampleService
{
public GetSampleServiceClient(UInt32 id) : base(id) { init(); }
void init()
{
for (int i = 0; i < Samples.Count(); i++)
{
Samples[i] = new SampleCell();
}
Features[0] = new SampleFeature();
Features[1] = new SampleFeature();
}
public GetSampleServiceClient(UInt32 serviceId, string connName) : base(serviceId, connName) { init(); }
#region IGetSampleService 成员
/// <summary>
......@@ -126,7 +112,7 @@ namespace FLY.Thick.Base.Client
range = Range,
window = Window,
IsCheckByPercent = IsCheckByPercent,
ErrPercent =ErrPercent,
ErrPercent = ErrPercent,
ErrValue = ErrValue,
search = Search,
samples = from sample in Samples
......@@ -159,6 +145,19 @@ namespace FLY.Thick.Base.Client
}
#endregion
public GetSampleServiceClient(UInt32 id) : base(id) { init(); }
public GetSampleServiceClient(UInt32 serviceId, string connName) : base(serviceId, connName) { init(); }
void init()
{
for (int i = 0; i < Samples.Count(); i++)
Samples[i] = new SampleCell();
for (int i = 0; i < Features.Count(); i++)
Features[i] = new SampleFeature();
}
public override void ConnectNotify(IFConn from)
{
......
......@@ -149,7 +149,6 @@ namespace FLY.Thick.Base.IService
/// </summary>
public int SampleValue { get; set; }
public bool IsChanged { get; set; }
#region INotifyPropertyChanged 成员
......@@ -206,7 +205,6 @@ namespace FLY.Thick.Base.IService
[DoNotCheckEquality]
public int[] ScanData { get; set; }
public bool IsChanged { get; set; }
#region INotifyPropertyChanged 成员
public event PropertyChangedEventHandler PropertyChanged;
......
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