WPF中的数据绑定(SCSM事件请求​​表)

时间:2014-06-19 18:04:41

标签: .net wpf winforms xaml data-binding

我目前正在开发一个SCSM(Microsoft Service Center Service Manager)2012项目,我必须创建一个自定义事件表单以便在控制台中使用。我试图在创作工具中扩展现有的表单,但发现它在功能上太有限了。因此,我开始在Visual Studio 2013中处理一个全新的表单(我假设我无法在VStudio中修改现有的事件表单程序集,否则这可能会使我的工作变得更容易)。我已经完成了表单的UI,并将其导入到创作工具中,以添加VStudio中不存在的一些功能(如列表选择器等)。现在我必须回到创作工具(或Visual Studio取决于你的答案)并专注于将文本框和控件绑定到实际数据......在这里我有点迷茫。我该怎么做呢?我知道我必须将文本框指向例如从哪里拉数据的位置,但是我在哪里从中提取数据呢?例如,状态,标题等。这些必须全部绑定到SMDB(Service Manager数据库)中的某个数据对象,但据我所知。任何指导,指针,提示,甚至我可以阅读的文档链接将不胜感激!我是WPF的一个完整的新手,并且一直在学习,所以如果可能的话,尽量减少行话并解释每一步。提前谢谢!

CODE

Incident_Request_Form.XAML.cs

    using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
/// using System.Threading.Tasks;
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;

namespace WpfControlLibrary1
{
    /// <summary>
    /// Interaction logic for UserControl1.xaml
    /// </summary>
    public partial class UserControl1 : UserControl
    {
        public UserControl1()
        {
            InitializeComponent();
        }
    }
}

Incident_Request_Form.xaml

<UserControl x:Class="WpfControlLibrary1.UserControl1"
             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" 
             mc:Ignorable="d" 
             d:DesignHeight="1000" d:DesignWidth="1024" Background="White">
    <Grid x:Name="Background_Grid" Width="1024" Height="1000" Background="White">
        <Grid.RowDefinitions>
            <RowDefinition Height="0*"/>
            <RowDefinition/>
        </Grid.RowDefinitions>
        <Rectangle Fill="#FFF4F4F5" HorizontalAlignment="Left" Height="144" Grid.RowSpan="2" Stroke="Black" VerticalAlignment="Top" Width="1024" StrokeThickness="5"/>
        <Image HorizontalAlignment="Left" Height="134" Grid.RowSpan="2" VerticalAlignment="Top" Width="560" Source="logo.png" Margin="10,10,0,0"/>
        <TabControl HorizontalAlignment="Left" Height="826" Margin="524,164,0,0" Grid.RowSpan="2" VerticalAlignment="Top" Width="490">
            <TabItem x:Name="Detail_Tab" Header="Incident Details" Cursor="Hand">
                <Grid Background="#FFE8F4F5" Margin="10,6,0,5.6">
                    <Rectangle x:Name="Assignment_Box_Copy1" Fill="#FF8FCBF7" HorizontalAlignment="Left" Height="40" Stroke="Black" VerticalAlignment="Top" Width="470" StrokeThickness="0"/>
                    <Label x:Name="Incident_Detail_Label" Content="Incident Detail" HorizontalAlignment="Left" Height="41" VerticalAlignment="Top" Width="355" Cursor="None" FontSize="24" FontWeight="Bold" FontFamily="Microsoft YaHei UI"/>
                    <Label x:Name="Category_Label" Content="Category:" HorizontalAlignment="Left" Margin="0,40,0,0" VerticalAlignment="Top"/>
                    <Label x:Name="Area_Label" Content="Area:" HorizontalAlignment="Left" Margin="0,66,0,0" VerticalAlignment="Top"/>
                    <Label x:Name="Subarea_Label" Content="Sub-Area:" HorizontalAlignment="Left" Margin="0,92,0,0" VerticalAlignment="Top"/>
                    <Label x:Name="Impact_Label" Content="Impact" HorizontalAlignment="Left" Margin="0,137,0,0" VerticalAlignment="Top"/>
                    <Label x:Name="Urgency_Label" Content="Urgency" HorizontalAlignment="Left" Margin="0,163,0,0" VerticalAlignment="Top"/>
                    <Label x:Name="Priority_Label" Content="Priority:" HorizontalAlignment="Left" Margin="0,189,0,0" VerticalAlignment="Top"/>
                    <Label x:Name="Service_Contract_Label" Content="Service Contract:" HorizontalAlignment="Left" Margin="0,235,0,0" VerticalAlignment="Top"/>
                    <Label x:Name="SLA_Target_Date_Label" Content="SLA Target Date:" HorizontalAlignment="Left" Margin="0,266,0,0" VerticalAlignment="Top"/>
                    <Label x:Name="Alert_Status_Label" Content="Alert Status:" HorizontalAlignment="Left" Margin="0,319,0,0" VerticalAlignment="Top"/>
                    <CheckBox x:Name="KB_Candidate_Checkbox" Content="Candiate for Knowledge DB" HorizontalAlignment="Left" Margin="10,390,0,0" VerticalAlignment="Top"/>
                    <Label x:Name="Hours_Worked_Label" Content="Hours Worked:" HorizontalAlignment="Left" Margin="0,411,0,0" VerticalAlignment="Top"/>
                    <Label x:Name="Closure_Code_Label" Content="Closure Code:" HorizontalAlignment="Left" Margin="0,436,0,0" VerticalAlignment="Top"/>
                    <Label x:Name="Solution_Label" Content="Solution:" HorizontalAlignment="Left" Margin="0,467,0,0" VerticalAlignment="Top"/>
                    <CheckBox x:Name="PM_Candidate_Checkbox" Content="Candidate for Problem Management" HorizontalAlignment="Left" Margin="192,390,0,0" VerticalAlignment="Top"/>
                </Grid>
            </TabItem>
            <TabItem x:Name="Activities_Tab" Header="Activities" Cursor="Hand">
                <Grid Background="#FFE8F4F5">
                    <Rectangle x:Name="Assignment_Box_Copy3" Fill="#FF8FCBF7" HorizontalAlignment="Left" Height="40" Stroke="Black" VerticalAlignment="Top" Width="470" StrokeThickness="0" Margin="10,10,0,0"/>
                    <Label x:Name="Activities_Label_Copy" Content="Activities" HorizontalAlignment="Left" Height="41" VerticalAlignment="Top" Width="355" Cursor="None" FontSize="24" FontWeight="Bold" FontFamily="Microsoft YaHei UI" Margin="10,10,0,0"/>
                    <TabControl HorizontalAlignment="Left" Height="728" Margin="10,56,0,0" VerticalAlignment="Top" Width="460">
                        <TabItem x:Name="Update_Tab" Header="Update">
                            <Grid x:Name="Update_Tab_Grid" Background="#FFE5E5E5">
                                <Label x:Name="Type_Label" Content="Type:" HorizontalAlignment="Left" Height="24" VerticalAlignment="Top" Cursor="None" FontWeight="Bold" Width="45" FontFamily="Microsoft JhengHei UI" Margin="10,10,0,0"/>
                                <CheckBox x:Name="Visible_2_Customers_Checkbox" Content="Visible To Customer?" HorizontalAlignment="Left" Margin="308,14,0,0" VerticalAlignment="Top"/>
                                <Label x:Name="Update_Label" Content="Update:" HorizontalAlignment="Left" Margin="10,39,0,0" VerticalAlignment="Top"/>
                                <TextBox x:Name="The_Update_TextBox" HorizontalAlignment="Left" Height="616" Margin="10,70,0,0" TextWrapping="Wrap" Text="TextBox" VerticalAlignment="Top" Width="431"/>
                            </Grid>
                        </TabItem>
                        <TabItem x:Name="Journal_Updates_Tab" Header="Journal Updates">
                            <Grid x:Name="Journal_Updates_Tab_Grid" Background="#FFE5E5E5">
                                <TextBlock x:Name="Journal_Update_Textblock" HorizontalAlignment="Left" Height="676" Margin="10,10,0,0" TextWrapping="Wrap" Text="TextBlock" VerticalAlignment="Top" Width="431"/>
                            </Grid>
                        </TabItem>
                        <TabItem x:Name="Historic_Activities_Tab" Header="Historic Activities" HorizontalAlignment="Left" Height="20" VerticalAlignment="Top">
                            <Grid x:Name="Historic_Activities_Tab_Grid" Background="#FFE5E5E5">
                                <Label x:Name="Filter_Label" Content="Filter By Activity Type:" HorizontalAlignment="Left" Margin="10,10,0,0" VerticalAlignment="Top" Height="28"/>
                                <Button x:Name="Filter_Button" Content="Filter" HorizontalAlignment="Left" Height="29" Margin="10,76,0,0" VerticalAlignment="Top" Width="125"/>
                            </Grid>
                        </TabItem>
                    </TabControl>
                </Grid>
            </TabItem>
            <TabItem x:Name="Related_Tab" Header="Related Records" HorizontalAlignment="Left" Height="20" VerticalAlignment="Top" Cursor="Hand">
                <Grid x:Name="Tabs" Background="#FFE5E5E5">
                    <TabControl HorizontalAlignment="Left" Height="774" Margin="10,10,0,0" VerticalAlignment="Top" Width="460">
                        <TabItem x:Name="Interactions_Tab" Header="Interactions">
                            <Grid Background="#FFE5E5E5"/>
                        </TabItem>
                        <TabItem x:Name="Incidents_Tab" Header="Incidents">
                            <Grid Background="#FFE5E5E5"/>
                        </TabItem>
                        <TabItem x:Name="Changes_Tab" Header="Changes" HorizontalAlignment="Left" Height="20" VerticalAlignment="Top">
                            <Grid Background="#FFE5E5E5"/>
                        </TabItem>
                        <TabItem x:Name="Quotes_Tab" Header="Quotes" HorizontalAlignment="Left" Height="20" VerticalAlignment="Top" Width="57.6">
                            <Grid Background="#FFE5E5E5"/>
                        </TabItem>
                        <TabItem x:Name="Problems_Tab" Header="Problems" HorizontalAlignment="Left" Height="20" VerticalAlignment="Top">
                            <Grid Background="#FFE5E5E5"/>
                        </TabItem>
                        <TabItem x:Name="RMA_Tab" Header="RMA" HorizontalAlignment="Left" Height="20" VerticalAlignment="Top" Width="57.6">
                            <Grid Background="#FFE5E5E5"/>
                        </TabItem>
                    </TabControl>
                </Grid>
            </TabItem>
            <TabItem x:Name="History_Tab" Header="History" HorizontalAlignment="Left" Height="20" VerticalAlignment="Top" Width="57.6">
                <Grid x:Name="Tab_Grid" Background="#FFE5E5E5" Cursor="Arrow"/>
            </TabItem>
            <TabItem x:Name="Attachment_Tab" Header="Attachments" HorizontalAlignment="Left" Height="20" VerticalAlignment="Top" Cursor="Hand">
                <Grid Background="#FFE5E5E5"/>
            </TabItem>
            <TabItem x:Name="Alerts_Tab" Header="Alerts" HorizontalAlignment="Left" Height="20" VerticalAlignment="Top" Width="57.6">
                <Grid Background="#FFE5E5E5"/>
            </TabItem>
        </TabControl>
        <Rectangle x:Name="Assignment_Box_Copy2" Fill="#FF8FCBF7" HorizontalAlignment="Left" Height="40" Margin="10,160,0,0" Stroke="Black" VerticalAlignment="Top" Width="499" StrokeThickness="0" Grid.RowSpan="2"/>
        <Label x:Name="Heading" Content="Incident Information" HorizontalAlignment="Left" Height="41" Margin="10,164,0,0" Grid.RowSpan="2" VerticalAlignment="Top" Width="355" Cursor="None" FontSize="24" FontWeight="Bold" FontFamily="Microsoft YaHei UI"/>
        <Grid x:Name="General_Information_Grid" HorizontalAlignment="Left" Height="785" Margin="10,205,0,0" Grid.RowSpan="2" VerticalAlignment="Top" Width="509">
            <Label x:Name="Incident_ID" Content="Incident ID:" HorizontalAlignment="Left" Height="24" VerticalAlignment="Top" Cursor="None" FontWeight="Bold" Width="75" FontFamily="Microsoft JhengHei UI"/>
            <Label x:Name="Status_Label" Content="Status:" HorizontalAlignment="Left" Height="24" VerticalAlignment="Top" Cursor="None" FontWeight="Bold" Width="75" FontFamily="Microsoft JhengHei UI" Margin="0,29,0,0"/>
            <Label x:Name="Status_Reasoning_Label" Content="Status Reasoning:" HorizontalAlignment="Left" VerticalAlignment="Top" Cursor="None" FontWeight="Bold" FontFamily="Microsoft JhengHei UI" Margin="0,53,0,0"/>
            <Rectangle x:Name="Assignment_Box" Fill="#FF8FCBF7" HorizontalAlignment="Left" Height="40" Margin="0,84,0,0" Stroke="Black" VerticalAlignment="Top" Width="499" StrokeThickness="0"/>
            <Label x:Name="Assignment_Label" Content="Assignment" Margin="0,84,223,0" Height="38" Width="137" FontSize="22" FontWeight="Bold" VerticalAlignment="Top" HorizontalAlignment="Left"/>
            <Label x:Name="Assignment_Group_Label" Content="Assignment Group:" HorizontalAlignment="Left" VerticalAlignment="Top" Cursor="None" FontWeight="Bold" FontFamily="Microsoft JhengHei UI" Margin="0,124,0,0"/>

            <Label x:Name="Assignee_Label" Content="Assignee:" HorizontalAlignment="Left" VerticalAlignment="Top" Cursor="None" FontWeight="Bold" FontFamily="Microsoft JhengHei UI" Margin="0,150,0,0"/>
            <Label x:Name="Vendor_Label" Content="Vendor:" HorizontalAlignment="Left" VerticalAlignment="Top" Cursor="None" FontWeight="Bold" FontFamily="Microsoft JhengHei UI" Margin="0,176,0,0"/>
            <Label x:Name="Reference_Number_Label" Content="Vendor Reference Number:" HorizontalAlignment="Left" VerticalAlignment="Top" Cursor="None" FontWeight="Bold" FontFamily="Microsoft JhengHei UI" Margin="0,202,0,0"/>
            <Rectangle x:Name="Assignment_Box_Copy" Fill="#FF8FCBF7" HorizontalAlignment="Left" Height="35" Margin="0,233,0,0" Stroke="Black" VerticalAlignment="Top" Width="499" StrokeThickness="0"/>
            <Label x:Name="Afected_Items" Content="Affected Items" Margin="0,230,0,0" Height="38" FontSize="22" FontWeight="Bold" VerticalAlignment="Top" HorizontalAlignment="Left" Width="165"/>
            <Label x:Name="Status_Label_Copy" Content="Status:" HorizontalAlignment="Left" Height="24" VerticalAlignment="Top" Cursor="None" FontWeight="Bold" Width="75" FontFamily="Microsoft JhengHei UI" Margin="0,29,0,0"/>
            <Label x:Name="Service_Label" Content="Service:" HorizontalAlignment="Left" VerticalAlignment="Top" Cursor="None" FontWeight="Bold" FontFamily="Microsoft JhengHei UI" Margin="0,277,0,0"/>
            <Label x:Name="Affected_CI_Label" Content="Affected CI:" HorizontalAlignment="Left" VerticalAlignment="Top" Cursor="None" FontWeight="Bold" FontFamily="Microsoft JhengHei UI" Margin="0,308,0,0"/>
            <CheckBox x:Name="Critical_CI_Checkbox" Content="Critical CI" HorizontalAlignment="Left" Margin="2,346,0,0" VerticalAlignment="Top"/>
            <CheckBox x:Name="Pending_Change_Checkbox" Content="Pending Change" HorizontalAlignment="Left" Margin="156,346,0,0" VerticalAlignment="Top"/>
            <CheckBox x:Name="CI_Operational_Checkbox" Content="CI is Operational (No Outage)" HorizontalAlignment="Left" Margin="326,346,0,0" VerticalAlignment="Top"/>
            <Label x:Name="Outage_Start_Label" Content="Outage Start:" HorizontalAlignment="Left" VerticalAlignment="Top" Cursor="None" FontWeight="Bold" FontFamily="Microsoft JhengHei UI" Margin="0,367,0,0"/>
            <Label x:Name="Outage_End_Label" Content="Outage End:" HorizontalAlignment="Left" VerticalAlignment="Top" Cursor="None" FontWeight="Bold" FontFamily="Microsoft JhengHei UI" Margin="0,393,0,0"/>
            <Label x:Name="Location_Label" Content="Location:" HorizontalAlignment="Left" VerticalAlignment="Top" Cursor="None" FontWeight="Bold" FontFamily="Microsoft JhengHei UI" Margin="0,424,0,0"/>
            <Label x:Name="Title_Label" Content="Title:" HorizontalAlignment="Left" VerticalAlignment="Top" Cursor="None" FontWeight="Bold" FontFamily="Microsoft JhengHei UI" Margin="0,455,0,0"/>
            <Label x:Name="Description_Label" Content="Description:" HorizontalAlignment="Left" VerticalAlignment="Top" Cursor="None" FontWeight="Bold" FontFamily="Microsoft JhengHei UI" Margin="0,521,0,0"/>
            <TextBox x:Name="Vendor_Reference_Textbox" HorizontalAlignment="Left" Height="26" Margin="199,202,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="300" ToolTip="Enter Vendor Reference # Here"/>
            <TextBox x:Name="Title_Textbox" HorizontalAlignment="Left" Height="26" Margin="10,486,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="489" ToolTip="Enter Vendor Reference # Here"/>
            <TextBox x:Name="Description_Textbox" HorizontalAlignment="Left" Height="228" Margin="10,547,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="489" ToolTip="Enter Vendor Reference # Here"/>
        </Grid>
    </Grid>
</UserControl>

1 个答案:

答案 0 :(得分:0)

你这样绑定它:

<TextBox Text="{Binding Path=Title, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"  Background="#FFECC3C3" Margin="5,0,10,0"/>

 <scwpf:SingleInstancePicker Instance="{Binding Path=Microsoft.SystemCenter.ConfigurationManager.MobileDevice, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" BaseClassId="c928e643-baa3-2cd7-3662-739befc4ac43" Margin="5,0,10,0"/>

同时查看此视频教程:

http://www.concurrency.com/blog/building-custom-forms-for-service-manager-with-visual-studio/

干杯 的Morten