前办场
<UserControl xmlns:toolkit="http://schemas.microsoft.com/winfx/2006/xaml/presentation/toolkit" x:Class="ComputerDropDragControl.ComputerUnit"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
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"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="400">
<Grid x:Name="LayoutRoot" Background="White">
<Button x:Name="btnComputer" Width="90" Height="40" VerticalAlignment="Top" HorizontalAlignment="Left" ></Button>
<toolkit:ContextMenuService.ContextMenu>
<toolkit:ContextMenu>
<toolkit:MenuItem Header="全屏" x:Name="miFudllScreen" Click="miFullScreen_Click"></toolkit:MenuItem>
<toolkit:MenuItem Header="告警" x:Name="miNotify" Click="miNotify_Click"></toolkit:MenuItem>
<toolkit:MenuItem Header="回收站" x:Name="miRecycle" Click="miRecycle_Click"></toolkit:MenuItem>
<toolkit:MenuItem Header="手推车" x:Name="miShop" Click="miShop_Click"></toolkit:MenuItem>
</toolkit:ContextMenu>
</toolkit:ContextMenuService.ContextMenu>
</Grid>
</UserControl>
后办场
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Collections.ObjectModel;
namespace ComputerDropDragControl
{
/// <summary>
/// 设备单元
/// 创建人:吴兆娟
/// 创建时间:2011-10-26
/// </summary>
public partial class ComputerUnit : UserControl
{
#region <<页面加载>>
/// <summary>
/// 页面加载
/// </summary>
public ComputerUnit(NodeFrameView entity)
{
InitializeComponent();
ReturnNodeFrameView = entity;
//初始化表单
InitForm();
}
TipWindow tipWindow = new TipWindow();
private bool showTip;
public bool ShowTip
{
get { return showTip; }
set
{
showTip = value;
if (showTip == true)
{
tipWindow.BindControl(this.btnComputer, ReturnNodeFrameView);
}
else
{
tipWindow.CancelBindControl(this.btnComputer);
}
}
}
/// <summary>
/// “初始化表单”
/// </summary>
private void InitForm()
{
btnComputer.Height = (btnComputer.Height) * ReturnNodeFrameView.NodeSize;
btnComputer.Content = ReturnNodeFrameView.NodeName;
ReturnHeight = btnComputer.Height;
}
#endregion
#region <<控件事件>>
#region <<右键菜单相关事件>>
/// <summary>
/// “全屏”
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void miFullScreen_Click(object sender, RoutedEventArgs e)
{
}
/// <summary>
/// “告警”
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void miNotify_Click(object sender, RoutedEventArgs e)
{
if (this.miNotify.Header.ToString() == "告警")
{
this.miNotify.Header = "取消告警";
this.btnComputer.Background = new SolidColorBrush(Colors.Orange);
//数据交互
}
else
{
this.miNotify.Header = "告警";
this.btnComputer.ClearValue(BackgroundProperty);
//数据交互
}
}
/// <summary>
/// “回收站”
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void miRecycle_Click(object sender, RoutedEventArgs e)
{
MessageBox.Show("数据交互");
}
/// <summary>
/// “手推车”
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void miShop_Click(object sender, RoutedEventArgs e)
{
MessageBox.Show("数据交互");
}
#endregion
#endregion
#region <<辅助方法>>
#endregion
public NodeFrameView ReturnNodeFrameView { get; set; }
public UIElement UI;
public ObservableCollection<NodeFrameView> NFList;
public double ReturnHeight { get; set; }
}
}