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

1. 整理 界面模块

parent 5aee9945
using Newtonsoft.Json.Linq; using Newtonsoft.Json.Linq;
using System; using System;
using System.CodeDom;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel; using System.ComponentModel;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using static Misc.BindingOperations;
namespace Misc namespace Misc
{ {
...@@ -51,7 +53,45 @@ namespace Misc ...@@ -51,7 +53,45 @@ namespace Misc
{ {
return GetValue<T>(key, default(T)); 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> /// <summary>
/// 获取值,如果没有返回默认值 /// 获取值,如果没有返回默认值
...@@ -84,6 +124,41 @@ namespace Misc ...@@ -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; private string path;
public event UiParamDictionaryValueChangedHandler ValueChanged; public event UiParamDictionaryValueChangedHandler ValueChanged;
...@@ -108,12 +183,21 @@ namespace Misc ...@@ -108,12 +183,21 @@ namespace Misc
} }
} }
public void Save() public void Save()
{
foreach (var cell in cells)
{ {
try try
{ {
foreach (var cell in cells)
cell.ToToken(); cell.ToToken();
}
catch (Exception e)
{
}
}
try
{
string json = Newtonsoft.Json.JsonConvert.SerializeObject(cells, Newtonsoft.Json.Formatting.Indented); string json = Newtonsoft.Json.JsonConvert.SerializeObject(cells, Newtonsoft.Json.Formatting.Indented);
File.WriteAllText(path, json); File.WriteAllText(path, json);
} }
...@@ -166,6 +250,13 @@ namespace Misc ...@@ -166,6 +250,13 @@ namespace Misc
return; return;
Value = Token.ToObject<T>(); Value = Token.ToObject<T>();
} }
public void ToValue(Type type)
{
IsConverted = true;
if (Token == null)
return;
Value = Token.ToObject(type);
}
public void ToToken() public void ToToken()
{ {
Token = JToken.FromObject(Value); Token = JToken.FromObject(Value);
......
...@@ -129,6 +129,57 @@ namespace Misc ...@@ -129,6 +129,57 @@ namespace Misc
}break; }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 ...@@ -92,28 +92,11 @@ namespace FLY.Thick.Base.UI.CustomSection
{ {
this.paramDictionary = paramDictionary; this.paramDictionary = paramDictionary;
this.lCUS1 = lCUS1; this.lCUS1 = lCUS1;
paramDictionary.SetBinding(this, "WarningTipPath", "");
WarningTipPath = this.paramDictionary.GetValue(ParamDistItemKeys.WarningTipPath, ""); paramDictionary.SetBinding(this, "WarningDurationSec", 5);
var v = this.paramDictionary.GetValue<int>(ParamDistItemKeys.WarningDurationSec); paramDictionary.SetBinding(this, "EnableScanErrBigTip", false);
WarningDurationSec = this.paramDictionary.GetValue(ParamDistItemKeys.WarningDurationSec, 5); paramDictionary.SetBinding(this, "LCUS1_PortName", "COM1");
EnableScanErrBigTip = this.paramDictionary.GetValue(ParamDistItemKeys.EnableScanErrBigTip, false); paramDictionary.SetBinding(this, "EnableLCUS1", 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);
};
} }
private void Play() private void Play()
......
...@@ -41,7 +41,6 @@ namespace FLY.Thick.Base.UI.CustomSection ...@@ -41,7 +41,6 @@ namespace FLY.Thick.Base.UI.CustomSection
public bool HaveOSK_mouse { get; set; } public bool HaveOSK_mouse { get; set; }
ParamDictionary paramDictionary;
public UcSectionOskVm() public UcSectionOskVm()
{ {
...@@ -49,16 +48,8 @@ namespace FLY.Thick.Base.UI.CustomSection ...@@ -49,16 +48,8 @@ namespace FLY.Thick.Base.UI.CustomSection
public void Init(ParamDictionary paramDictionary) public void Init(ParamDictionary paramDictionary)
{ {
this.paramDictionary = paramDictionary; paramDictionary.SetBinding(this, "HaveOSK", false);
HaveOSK = paramDictionary.GetValue(ParamDistItemKeys.HaveOSK, true); paramDictionary.SetBinding(this, "HaveOSK_mouse", false);
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);
};
} }
} }
......
...@@ -203,6 +203,9 @@ ...@@ -203,6 +203,9 @@
<Compile Include="PgPwManager.xaml.cs"> <Compile Include="PgPwManager.xaml.cs">
<DependentUpon>PgPwManager.xaml</DependentUpon> <DependentUpon>PgPwManager.xaml</DependentUpon>
</Compile> </Compile>
<Compile Include="UiModule\DynAreaFilmWidth.xaml.cs">
<DependentUpon>DynAreaFilmWidth.xaml</DependentUpon>
</Compile>
<Compile Include="UiModule\DynAreaIO.xaml.cs"> <Compile Include="UiModule\DynAreaIO.xaml.cs">
<DependentUpon>DynAreaIO.xaml</DependentUpon> <DependentUpon>DynAreaIO.xaml</DependentUpon>
</Compile> </Compile>
...@@ -371,6 +374,10 @@ ...@@ -371,6 +374,10 @@
<Generator>MSBuild:Compile</Generator> <Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType> <SubType>Designer</SubType>
</Page> </Page>
<Page Include="UiModule\DynAreaFilmWidth.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Page Include="UiModule\DynAreaIO.xaml"> <Page Include="UiModule\DynAreaIO.xaml">
<Generator>MSBuild:Compile</Generator> <Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType> <SubType>Designer</SubType>
......
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
<Grid > <Grid >
<Grid.RowDefinitions> <Grid.RowDefinitions>
<RowDefinition Height="auto" /> <RowDefinition Height="auto" />
<RowDefinition Height="496*" /> <RowDefinition />
</Grid.RowDefinitions> </Grid.RowDefinitions>
<Grid Background="{StaticResource Background_Title}" > <Grid Background="{StaticResource Background_Title}" >
<Grid.ColumnDefinitions> <Grid.ColumnDefinitions>
......
...@@ -24,22 +24,27 @@ ...@@ -24,22 +24,27 @@
<RowDefinition Height="auto" /> <RowDefinition Height="auto" />
<RowDefinition /> <RowDefinition />
</Grid.RowDefinitions> </Grid.RowDefinitions>
<Grid Name="grid_null"/> <Grid Background="{StaticResource Background_Title}" >
<StackPanel Orientation="Horizontal" Background="{StaticResource Background_Title}"> <Grid.ColumnDefinitions>
<Button Style="{StaticResource ButtonStyle_back2}" Command="BrowseBack"/> <ColumnDefinition/>
<ColumnDefinition Width="auto"/>
</Grid.ColumnDefinitions>
<StackPanel Orientation="Horizontal" >
<Button Style="{StaticResource ButtonStyle_back2}" Command="BrowseBack" />
<TextBlock Style="{StaticResource TextBlockStyle_Title}" Text="机架信息"/> <TextBlock Style="{StaticResource TextBlockStyle_Title}" Text="机架信息"/>
</StackPanel> </StackPanel>
<local:CtMicroGage Grid.Column="1" x:Name="mircoGage" Background="Transparent" VerticalAlignment="Bottom"/>
</Grid>
<Grid Grid.Row="1" Margin="0,5,0,5"> <Grid Grid.Row="1" Margin="0,5,0,5">
<Grid.ColumnDefinitions> <Grid.ColumnDefinitions>
<ColumnDefinition Width="auto" /> <ColumnDefinition Width="auto" />
<ColumnDefinition/> <ColumnDefinition/>
</Grid.ColumnDefinitions> </Grid.ColumnDefinitions>
<Button Click="button_start_Click" > <Button Click="button_start_Click" >
<TextBlock Text="录制" > <TextBlock >
<TextBlock.Style> <TextBlock.Style>
<Style TargetType="TextBlock" BasedOn="{StaticResource TextStyle_paramSection}" > <Style TargetType="TextBlock" BasedOn="{StaticResource TextStyle_paramSection}" >
<Setter Property="Text" Value="录制"/>
<Style.Triggers> <Style.Triggers>
<DataTrigger Binding="{Binding IsRunning}" Value="True"> <DataTrigger Binding="{Binding IsRunning}" Value="True">
<Setter Property="Text" Value="停止"/> <Setter Property="Text" Value="停止"/>
......
...@@ -40,6 +40,7 @@ namespace FLY.Thick.Base.UI ...@@ -40,6 +40,7 @@ namespace FLY.Thick.Base.UI
this.getSample = getSample; this.getSample = getSample;
this.borderSearch = borderSearch; this.borderSearch = borderSearch;
this.container = container; this.container = container;
container.BuildUp(mircoGage);
} }
private void Page_Loaded(object sender, RoutedEventArgs e1) private void Page_Loaded(object sender, RoutedEventArgs e1)
{ {
...@@ -99,6 +100,9 @@ namespace FLY.Thick.Base.UI ...@@ -99,6 +100,9 @@ namespace FLY.Thick.Base.UI
{ {
update(); update();
}; };
DataBindAll();
update();
} }
void InitializeComponent2() void InitializeComponent2()
......
...@@ -22,8 +22,7 @@ ...@@ -22,8 +22,7 @@
<Grid > <Grid >
<Grid.RowDefinitions> <Grid.RowDefinitions>
<RowDefinition Height="auto" /> <RowDefinition Height="auto" />
<RowDefinition Height="496*" /> <RowDefinition />
<RowDefinition Height="auto" />
</Grid.RowDefinitions> </Grid.RowDefinitions>
<StackPanel Orientation="Horizontal" Background="{StaticResource Brush_theme_bar}"> <StackPanel Orientation="Horizontal" Background="{StaticResource Brush_theme_bar}">
<Button Style="{StaticResource ButtonStyle_back2}" Command="BrowseBack"/> <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 ...@@ -19,20 +19,6 @@ namespace FLY.Thick.Base.Client
[JsonObject(MemberSerialization.OptIn)] [JsonObject(MemberSerialization.OptIn)]
public class GetSampleServiceClient : FObjServiceClient, IGetSampleService 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 成员 #region IGetSampleService 成员
/// <summary> /// <summary>
...@@ -126,7 +112,7 @@ namespace FLY.Thick.Base.Client ...@@ -126,7 +112,7 @@ namespace FLY.Thick.Base.Client
range = Range, range = Range,
window = Window, window = Window,
IsCheckByPercent = IsCheckByPercent, IsCheckByPercent = IsCheckByPercent,
ErrPercent =ErrPercent, ErrPercent = ErrPercent,
ErrValue = ErrValue, ErrValue = ErrValue,
search = Search, search = Search,
samples = from sample in Samples samples = from sample in Samples
...@@ -159,6 +145,19 @@ namespace FLY.Thick.Base.Client ...@@ -159,6 +145,19 @@ namespace FLY.Thick.Base.Client
} }
#endregion #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) public override void ConnectNotify(IFConn from)
{ {
......
...@@ -149,7 +149,6 @@ namespace FLY.Thick.Base.IService ...@@ -149,7 +149,6 @@ namespace FLY.Thick.Base.IService
/// </summary> /// </summary>
public int SampleValue { get; set; } public int SampleValue { get; set; }
public bool IsChanged { get; set; }
#region INotifyPropertyChanged 成员 #region INotifyPropertyChanged 成员
...@@ -206,7 +205,6 @@ namespace FLY.Thick.Base.IService ...@@ -206,7 +205,6 @@ namespace FLY.Thick.Base.IService
[DoNotCheckEquality] [DoNotCheckEquality]
public int[] ScanData { get; set; } public int[] ScanData { get; set; }
public bool IsChanged { get; set; }
#region INotifyPropertyChanged 成员 #region INotifyPropertyChanged 成员
public event PropertyChangedEventHandler PropertyChanged; 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