Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <Window x:Class="Hipot_Sequence_Editor.MainWindow"
- 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"
- xmlns:local="clr-namespace:Hipot_Sequence_Editor"
- xmlns:viewModels="clr-namespace:Hipot_Sequence_Editor"
- xmlns:views="clr-namespace:Hipot_Sequence_Editor.Views"
- mc:Ignorable="d"
- Title="MainWindow" Height="677.538" Width="896.456" Name="mainWindow" Loaded="mainWindow_Loaded">
- <Window.DataContext>
- <local:VM_Main></local:VM_Main>
- </Window.DataContext>
- <Grid>
- <Grid.RowDefinitions>
- <RowDefinition Height="25*"/>
- <RowDefinition Height="299*"/>
- </Grid.RowDefinitions>
- <Grid.ColumnDefinitions>
- <ColumnDefinition Width="211*"/>
- <ColumnDefinition Width="86*"/>
- </Grid.ColumnDefinitions>
- <TreeView x:Name="treeView" Grid.Column="1" HorizontalAlignment="Left" Height="628" Margin="10.2,10,0,0" VerticalAlignment="Top" Width="237" Grid.RowSpan="2" ItemsSource="{Binding Parts}" SelectedItemChanged="TreeView_OnSelectedItemChanged">
- <TreeView.Resources>
- <HierarchicalDataTemplate x:Name="PartLevel" DataType="{x:Type viewModels:VM_Part}" ItemsSource="{Binding VM_Steps}">
- <StackPanel Orientation="Horizontal">
- <TextBlock Text="{Binding SequenceNumber}" />
- <TextBlock Text=" - "></TextBlock>
- <TextBlock Text="{Binding Name}" />
- </StackPanel>
- </HierarchicalDataTemplate>
- <DataTemplate DataType="{x:Type viewModels:VM_Step}">
- <StackPanel Orientation="Horizontal">
- <CheckBox Visibility="{Binding Path=DataContext.CheckMarksVisible, ElementName=PartLevel}"></CheckBox>
- <TextBlock Text="{Binding Name}" />
- </StackPanel>
- </DataTemplate>
- </TreeView.Resources>
- </TreeView>
- <ContentControl Grid.Row="1" Grid.Column="0" x:Name="ContentPanel" Content="{Binding TreeViewSelectedItem}">
- <ContentControl.Resources>
- <DataTemplate DataType="{x:Type local:VM_Part}">
- <Label Content="{Binding Name}"></Label>
- </DataTemplate>
- <DataTemplate DataType="{x:Type local:VM_Step}">
- <views:StepEditorView/>
- </DataTemplate>
- </ContentControl.Resources>
- </ContentControl>
- </Grid>
- </Window>
- using System.Collections.ObjectModel;
- using System.Windows;
- namespace Hipot_Sequence_Editor
- {
- /// <summary>
- /// Interaction logic for MainWindow.xaml
- /// </summary>
- public partial class MainWindow : Window
- {
- private VM_Main _viewModel;
- public MainWindow()
- {
- InitializeComponent();
- _viewModel = (VM_Main)DataContext;
- }
- private void TreeView_OnSelectedItemChanged(object sender, RoutedPropertyChangedEventArgs<object> e)
- {
- _viewModel.TreeViewSelectedItem = e.NewValue;
- }
- private void mainWindow_Loaded(object sender, RoutedEventArgs e)
- {
- _viewModel.Parts = new ObservableCollection<VM_Part>
- {
- new VM_Part()
- {
- Name = "Sequence 1",
- SequenceNumber = 1,
- VM_Steps = new ObservableCollection<VM_Step>()
- {
- new VM_Step() {
- Name = "Step 1",
- TestType = TestType.DCW,
- VM_Step_Test = new VM_Step_Test()
- {
- Voltage = 50,
- RampTime = 33,
- DwellTime = 20,
- TestTimeResistance = 30,
- }
- },
- new VM_Step() {
- Name = "Step 2",
- TestType = TestType.DCW,
- VM_Step_Test = new VM_Step_Test()
- {
- Voltage = 55,
- RampTime = 34,
- DwellTime = 23,
- TestTimeResistance = 23,
- }
- },
- new VM_Step() {
- Name = "Step 3",
- TestType = TestType.LOWOHM,
- VM_Step_Test = new VM_Step_Test()
- {
- TestTimeResistance = 30,
- MaxResistance = 100
- }
- }
- }
- },
- new VM_Part()
- {
- Name = "Sequence 2",
- SequenceNumber = 2,
- VM_Steps = new ObservableCollection<VM_Step>()
- {
- new VM_Step() {
- Name = "Step 1",
- TestType = TestType.DCW,
- VM_Step_Test = new VM_Step_Test()
- {
- Voltage = 23,
- RampTime = 21,
- DwellTime = 10,
- TestTimeResistance = 05,
- }
- },
- new VM_Step() {
- Name = "Step 2",
- TestType = TestType.DCW,
- VM_Step_Test = new VM_Step_Test()
- {
- Voltage = 55,
- RampTime = 56,
- DwellTime = 53,
- TestTimeResistance = 46,
- }
- },
- new VM_Step() {
- Name = "Step 3",
- TestType = TestType.LOWOHM,
- VM_Step_Test = new VM_Step_Test()
- {
- TestTimeResistance = 989,
- MaxResistance = 75
- }
- }
- }
- }
- };
- }
- }
- }
- <UserControl x:Class="Hipot_Sequence_Editor.Views.StepEditorView"
- 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"
- xmlns:dataModel="clr-namespace:Hardware.DataModel;assembly=Vitrek-Library"
- xmlns:uiConverters="clr-namespace:Hipot_Sequence_Editor.UI_Converters"
- mc:Ignorable="d"
- d:DesignHeight="300" d:DesignWidth="300">
- <UserControl.Resources>
- <uiConverters:DoubleStringConverter x:Key="DoubleStringConverter" />
- <uiConverters:EnumSelectedConverter x:Key="EnumSelectedConverter" />
- </UserControl.Resources>
- <Grid>
- <Grid.RowDefinitions>
- <RowDefinition Height="25"/>
- <RowDefinition Height="100"/>
- </Grid.RowDefinitions>
- <Grid.ColumnDefinitions>
- <ColumnDefinition Width="*" />
- </Grid.ColumnDefinitions>
- <WrapPanel Grid.Row="0">
- <Label>Step: </Label>
- <Label Content="{Binding Name}"></Label>
- </WrapPanel>
- <TabControl Grid.Row="1">
- <TabItem Header="Resistance" IsSelected="{Binding VM_Step_Test.vTestType, Converter={StaticResource EnumSelectedConverter}, ConverterParameter={x:Static dataModel:TestType.LOWOHM}}">
- <WrapPanel>
- <WrapPanel>
- <Label Content="Resistance"></Label>
- <TextBox Width="50" Text="{Binding VM_Step_Test.MaxResistance, Converter={StaticResource DoubleStringConverter}}"></TextBox>
- <Label Content="Ω"></Label>
- </WrapPanel>
- <WrapPanel>
- <Label Content="Dwell Time"></Label>
- <TextBox Width="50" Text="{Binding VM_Step_Test.TestTimeResistance, Converter={StaticResource DoubleStringConverter}}"></TextBox>
- <Label Content="mSec"></Label>
- </WrapPanel>
- </WrapPanel>
- </TabItem>
- <TabItem Header="DC Hipot" IsSelected="{Binding VM_Step_Test.vTestType, Converter={StaticResource EnumSelectedConverter}, ConverterParameter={x:Static dataModel:TestType.DCW}}" Height="22" VerticalAlignment="Top">
- <WrapPanel>
- <WrapPanel>
- <Label Content="Voltage"></Label>
- <TextBox Width="50" Text="{Binding VM_Step_Test.Voltage, Converter={StaticResource DoubleStringConverter}}"></TextBox>
- <Label Content="kV"></Label>
- </WrapPanel>
- <WrapPanel>
- <Label Content="Ramp Time"></Label>
- <TextBox Width="50" Text="{Binding VM_Step_Test.RampTime, Converter={StaticResource DoubleStringConverter}}"></TextBox>
- <Label Content="mSec"></Label>
- </WrapPanel>
- <WrapPanel>
- <Label Content="Dwell Time"></Label>
- <TextBox Width="50" Text="{Binding VM_Step_Test.DwellTime, Converter={StaticResource DoubleStringConverter}}"></TextBox>
- <Label Content="mSec"></Label>
- </WrapPanel>
- </WrapPanel>
- </TabItem>
- </TabControl>
- </Grid>
- </UserControl>
- using System;
- using System.Collections.ObjectModel;
- using System.ComponentModel;
- using PropertyChanged;
- namespace Hipot_Sequence_Editor
- {
- [AddINotifyPropertyChangedInterface]
- public class VM_Main
- {
- private object _treeViewSelectedItem;
- public ObservableCollection<VM_Part> Parts { get; set; }
- public object TreeViewSelectedItem
- {
- get => _treeViewSelectedItem;
- set { _treeViewSelectedItem = value; OnSelectedNodeChanged(value); }
- }
- public VM_Part SelectedPartForUI { get; set; }
- public VM_Step SelectedStepForUI { get; set; }
- public VM_Step_Test SelectedTestStepForUI { get; set; }
- private void OnSelectedNodeChanged(object node)
- {
- switch (node)
- {
- case VM_Part vmpart:
- SelectedPartForUI = vmpart;
- break;
- case VM_Step vmstep:
- SelectedStepForUI = vmstep;
- break;
- default:
- throw new NotImplementedException();
- }
- }
- }
- public enum TestType
- {
- [Description("AC Hipot")]
- ACW,
- [Description("DC Hipot")]
- DCW,
- [Description("Resistance")]
- LOWOHM
- }
- [AddINotifyPropertyChangedInterface]
- public class VM_Part
- {
- public int SequenceNumber { get; set; }
- public string Name { get; set; }
- public ObservableCollection<VM_Step> VM_Steps { get; set; }
- public bool IsSelected { get; set; }
- public bool CheckMarksVisible { get; set; }
- }
- [AddINotifyPropertyChangedInterface]
- public class VM_Step
- {
- public string Name { get; set; }
- public TestType TestType { get; set; }
- public VM_Step_Test VM_Step_Test { get; set; }
- public bool IsSelected { get; set; }
- }
- [AddINotifyPropertyChangedInterface]
- public class VM_Step_Test
- {
- public TestType vTestType { get; set; }
- public double RampTime { get; set; }
- public double DwellTime { get; set; }
- public double Voltage { get; set; }
- public double TestTimeResistance { get; set; }
- public double MaxResistance { get; set; }
- }
- }
- using System.Windows.Data;
- namespace Hipot_Sequence_Editor.UI_Converters
- {
- public class EnumSelectedConverter : IValueConverter
- {
- public object Convert(object value, Type targetType,
- object parameter, System.Globalization.CultureInfo culture)
- {
- if (value == null || parameter == null) return false;
- TestType vmType = (TestType) value;
- TestType viewType = (TestType) parameter;
- return vmType == viewType;
- }
- public object ConvertBack(object value, Type targetType,
- object parameter, System.Globalization.CultureInfo culture)
- {
- if (value == null || parameter == null) return false;
- bool isSelected = (bool) value;
- if (!isSelected) return false;
- TestType vTestType = (TestType) parameter;
- return vTestType;
- }
- }
- }
- using System;
- using System.Windows.Data;
- namespace Hipot_Sequence_Editor.UI_Converters
- {
- public class DoubleStringConverter : IValueConverter
- {
- private string user_string = null;
- public object Convert(object value, Type targetType,
- object parameter, System.Globalization.CultureInfo culture)
- {
- if (user_string != null)
- {
- return user_string;
- }
- double number = (double)value;
- return string.Format(System.Globalization.CultureInfo.CurrentCulture, "{0}", number);
- }
- public object ConvertBack(object value, Type targetType,
- object parameter, System.Globalization.CultureInfo culture)
- {
- string s_value = value.ToString();
- double result = 0;
- System.Text.RegularExpressions.Regex nonNumericCharacters = new System.Text.RegularExpressions.Regex(@"[^0-9.]");
- string numericOnlyString = nonNumericCharacters.Replace(s_value, String.Empty);
- if (!double.TryParse(numericOnlyString, System.Globalization.NumberStyles.Number,
- System.Globalization.CultureInfo.CurrentCulture, out result))
- return null;
- user_string = s_value;
- return result;
- }
- }
- }
Add Comment
Please, Sign In to add comment