Commit 5d631bd5 authored by 潘栩锋's avatar 潘栩锋 🚴
parents 3d9c1da0 e1cebe18
...@@ -3,6 +3,7 @@ using System.Collections.Generic; ...@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Reflection; using System.Reflection;
using System.Text; using System.Text;
using System.Text.RegularExpressions;
namespace Misc namespace Misc
{ {
...@@ -28,6 +29,8 @@ namespace Misc ...@@ -28,6 +29,8 @@ namespace Misc
/// <param name="v"></param> /// <param name="v"></param>
public static void SetValue(object obj, string propertyName, object v) public static void SetValue(object obj, string propertyName, object v)
{ {
//if (!getRootProperty(ref obj, ref propertyName))
// return;
PropertyInfo property = obj.GetType().GetProperty(propertyName); PropertyInfo property = obj.GetType().GetProperty(propertyName);
if (property != null) if (property != null)
{ {
...@@ -35,6 +38,36 @@ namespace Misc ...@@ -35,6 +38,36 @@ namespace Misc
} }
} }
static bool getRootProperty(ref object obj, ref string propertyName) {
Regex r = new Regex(@"(\S+)\[(\d+)\]");
string[] lvs = propertyName.Split('.');
if (lvs.Count() > 1)
{
//这个是多级的
for (int i = 0; i < lvs.Count() - 1; i++)
{
PropertyInfo property;
string name = lvs[i];
int index = 0;
var match = r.Match(name);
if (match.Success)
{
name = match.Groups[1].Value;
index = int.Parse(match.Groups[2].Value);
}
property = obj.GetType().GetProperty(name);
if (property == null)
return false;//异常
if(match.Success)
obj = property.GetValue(obj,new object[] { index });
else
obj = property.GetValue(obj);
}
propertyName = lvs.Last();
}
return true;
}
/// <summary> /// <summary>
/// 设定参数(属性)的值,触发属性值变化“通知”,writeVal /// 设定参数(属性)的值,触发属性值变化“通知”,writeVal
/// </summary> /// </summary>
...@@ -43,6 +76,9 @@ namespace Misc ...@@ -43,6 +76,9 @@ namespace Misc
/// <param name="val"></param> /// <param name="val"></param>
public static void SetValue(object obj, string propertyName, string val) public static void SetValue(object obj, string propertyName, string val)
{ {
//if (!getRootProperty(ref obj, ref propertyName))
// return;
PropertyInfo property = obj.GetType().GetProperty(propertyName); PropertyInfo property = obj.GetType().GetProperty(propertyName);
if (property != null) if (property != null)
{ {
...@@ -59,6 +95,9 @@ namespace Misc ...@@ -59,6 +95,9 @@ namespace Misc
/// <returns></returns> /// <returns></returns>
public static object GetValue(object obj, string propertyName) public static object GetValue(object obj, string propertyName)
{ {
//if (!getRootProperty(ref obj, ref propertyName))
// return null;
PropertyInfo property = obj.GetType().GetProperty(propertyName); PropertyInfo property = obj.GetType().GetProperty(propertyName);
if (property != null) if (property != null)
{ {
......
...@@ -13,6 +13,10 @@ ...@@ -13,6 +13,10 @@
<ResourceDictionary Source="pack://application:,,,/FLY.ControlLibrary;component/Themes/Dictionary_MyStyle.xaml"/> <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 Source="pack://application:,,,/FLY.Thick.Base.UI;component/Converter/Dictionary_MyConv.xaml"/>
</ResourceDictionary.MergedDictionaries> </ResourceDictionary.MergedDictionaries>
<Style TargetType="DataGridCell" >
<Setter Property="FontSize" Value="16"/>
</Style>
</ResourceDictionary> </ResourceDictionary>
</Page.Resources> </Page.Resources>
<Grid Name="root_grid" > <Grid Name="root_grid" >
...@@ -42,27 +46,13 @@ ...@@ -42,27 +46,13 @@
</StackPanel> </StackPanel>
</Grid> </Grid>
<Grid x:Name="grid_window" Grid.Row="1">
<Grid Grid.Row="1">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="auto" />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Border Style="{StaticResource BorderStyle_paramSection}" >
<TextBlock Text="历史报警&#x0a;列表" />
</Border>
<Grid Grid.Column="1" x:Name="grid_window">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="751*"/>
<ColumnDefinition Width="54*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions> <Grid.RowDefinitions>
<RowDefinition Height="auto"/> <RowDefinition Height="auto"/>
<RowDefinition/> <RowDefinition/>
</Grid.RowDefinitions> </Grid.RowDefinitions>
<Grid Grid.ColumnSpan="2"> <Grid >
<Grid.ColumnDefinitions> <Grid.ColumnDefinitions>
<ColumnDefinition/> <ColumnDefinition/>
<ColumnDefinition Width="auto"/> <ColumnDefinition Width="auto"/>
...@@ -94,12 +84,10 @@ ...@@ -94,12 +84,10 @@
</StackPanel> </StackPanel>
</Grid> </Grid>
<DataGrid Grid.Row="1" ItemsSource="{Binding Record}" AutoGenerateColumns="False" IsReadOnly="True" Grid.ColumnSpan="2" AlternationCount="5" > <DataGrid Grid.Row="1" ItemsSource="{Binding Record}" AutoGenerateColumns="False" IsReadOnly="True" Grid.ColumnSpan="2"
<DataGrid.CellStyle> AlternationCount="5" AlternatingRowBackground="LightGray"
<Style TargetType="DataGridCell"> >
<Setter Property="FontSize" Value="20"/>
</Style>
</DataGrid.CellStyle>
<DataGrid.Columns> <DataGrid.Columns>
<DataGridTextColumn Binding="{Binding Time,StringFormat={}{0:MM/dd HH:mm}}" > <DataGridTextColumn Binding="{Binding Time,StringFormat={}{0:MM/dd HH:mm}}" >
<DataGridTextColumn.Header> <DataGridTextColumn.Header>
...@@ -133,7 +121,7 @@ ...@@ -133,7 +121,7 @@
</DataGrid> </DataGrid>
</Grid> </Grid>
</Grid>
......
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