using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Aitex.Core.Common.DeviceData;
namespace Aitex.Core.UI.DeviceControl
{
///
/// AITSensor.xaml 的交互逻辑
///
public partial class AITSensor : UserControl
{
public static readonly DependencyProperty DeviceDataProperty = DependencyProperty.Register(
"DeviceData", typeof(AITSensorData), typeof(AITSensor),
new FrameworkPropertyMetadata(new AITSensorData(), FrameworkPropertyMetadataOptions.AffectsRender));
public AITSensorData DeviceData
{
get
{
return (AITSensorData)this.GetValue(DeviceDataProperty);
}
set
{
this.SetValue(DeviceDataProperty, value);
}
}
///
/// 如果是InterlockSensor,value==1 就变红
///
public static readonly DependencyProperty IsInterlockSensorProperty = DependencyProperty.Register(
"IsInterlockSensor", typeof(bool), typeof(AITSensor),
new FrameworkPropertyMetadata(true, FrameworkPropertyMetadataOptions.AffectsRender));
public bool IsInterlockSensor
{
get
{
return (bool)this.GetValue(IsInterlockSensorProperty);
}
set
{
this.SetValue(IsInterlockSensorProperty, value);
}
}
public AITSensor()
{
InitializeComponent();
}
protected override void OnRender(DrawingContext drawingContext)
{
base.OnRender(drawingContext);
if (DeviceData == null)
{
sensor.Fill = new SolidColorBrush(Colors.Gray);
return;
}
if (IsInterlockSensor)
{
if (DeviceData.IsError)
sensor.Fill = new SolidColorBrush(Colors.Red);
else
{
sensor.Fill = new SolidColorBrush(Colors.Lime);
}
return;
}
if (DeviceData.Value)
{
sensor.Fill = new SolidColorBrush(Colors.Lime);
}
else
{
sensor.Fill = new SolidColorBrush(Colors.Gray);
}
}
private void Grid_MouseEnter(object sender, MouseEventArgs e)
{
if (DeviceData != null)
{
string tooltipValue =
string.Format(Application.Current.Resources["GlobalLableSensorToolTip"].ToString(),
"Sensor",
DeviceData.DisplayName,
DeviceData.DeviceSchematicId,
DeviceData.Value );
ToolTip = tooltipValue;
}
}
}
}