Push Alpha Version
This commit is contained in:
52
uniper_hmi_old/UniperHMI/SettingsPage/SettingsPage.xaml
Normal file
52
uniper_hmi_old/UniperHMI/SettingsPage/SettingsPage.xaml
Normal file
@@ -0,0 +1,52 @@
|
||||
<Page x:Class="InfineonHMI.SettingsPage"
|
||||
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:mah="clr-namespace:MahApps.Metro.Controls;assembly=MahApps.Metro"
|
||||
xmlns:local="clr-namespace:InfineonHMI"
|
||||
mc:Ignorable="d"
|
||||
d:DesignHeight="450" d:DesignWidth="800"
|
||||
d:DataContext="{d:DesignInstance Type=local:SettingsPageVM}"
|
||||
Title="SettingsPageView">
|
||||
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition/>
|
||||
<RowDefinition/>
|
||||
<RowDefinition/>
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<Button x:Name="BtnReadIni"
|
||||
Content="Ini Datei einlesen"
|
||||
Width="120"
|
||||
HorizontalAlignment="Left"
|
||||
Margin="10"/>
|
||||
|
||||
<!-- {d:SampleData ItemCount=5} -->
|
||||
<!--<DataGrid d:ItemsSource="{Binding CollectionView.View}"/>-->
|
||||
|
||||
|
||||
|
||||
<TreeView x:Name="treeview" ItemsSource="{Binding RootItem}" SelectedValuePath="Value" MinWidth="200" >
|
||||
<TreeView.ItemTemplate>
|
||||
<HierarchicalDataTemplate ItemsSource="{Binding SubEntries}">
|
||||
<TreeViewItem>
|
||||
<TreeViewItem.Header>
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="*"/>
|
||||
<ColumnDefinition Width="Auto" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<Label Content="{Binding Path=Name}"/>
|
||||
<TextBox Text="{Binding Value}" Visibility="{Binding Visibility}" Margin="10,0,0,0" Width="150" TextAlignment="Right"/>
|
||||
</Grid>
|
||||
</TreeViewItem.Header>
|
||||
<!-- <TextBox Text="{Binding Value}" Visibility="{Binding Visibility}"/> -->
|
||||
</TreeViewItem>
|
||||
</HierarchicalDataTemplate>
|
||||
</TreeView.ItemTemplate>
|
||||
</TreeView>
|
||||
</Grid>
|
||||
</Page>
|
||||
22
uniper_hmi_old/UniperHMI/SettingsPage/SettingsPage.xaml.cs
Normal file
22
uniper_hmi_old/UniperHMI/SettingsPage/SettingsPage.xaml.cs
Normal file
@@ -0,0 +1,22 @@
|
||||
using System.Windows.Controls;
|
||||
|
||||
namespace InfineonHMI
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaktionslogik für SettingsPageView.xaml
|
||||
/// </summary>
|
||||
public partial class SettingsPage : Page
|
||||
{
|
||||
public SettingsPage()
|
||||
{
|
||||
InitializeComponent();
|
||||
Unloaded += OnUnloaded;
|
||||
}
|
||||
|
||||
private void OnUnloaded(object? sender, EventArgs e)
|
||||
{
|
||||
var disposable = DataContext as IDisposable;
|
||||
disposable?.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
125
uniper_hmi_old/UniperHMI/SettingsPage/SettingsPageVM.cs
Normal file
125
uniper_hmi_old/UniperHMI/SettingsPage/SettingsPageVM.cs
Normal file
@@ -0,0 +1,125 @@
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using MahApps.Metro.Controls;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Diagnostics;
|
||||
using System.Windows;
|
||||
using TwinCAT.Ads.TypeSystem;
|
||||
using TwinCAT.TypeSystem;
|
||||
using Heisig.HMI.AdsManager;
|
||||
|
||||
namespace InfineonHMI
|
||||
{
|
||||
public partial class SettingsEntry : ObservableObject
|
||||
{
|
||||
[ObservableProperty]
|
||||
private string name = "";
|
||||
|
||||
[ObservableProperty]
|
||||
private string instancePath = "";
|
||||
|
||||
[ObservableProperty]
|
||||
private string? dataType;
|
||||
|
||||
[ObservableProperty]
|
||||
private Object? value;
|
||||
|
||||
public ObservableCollection<SettingsEntry> SubEntries { get; set; } = [];
|
||||
|
||||
[ObservableProperty]
|
||||
private Visibility visibility = Visibility.Collapsed;
|
||||
|
||||
private readonly IAdsManager _adsManager;
|
||||
|
||||
public SettingsEntry(IAdsManager adsManager)
|
||||
{
|
||||
_adsManager = adsManager;
|
||||
}
|
||||
|
||||
partial void OnValueChanging(object? oldValue, object? newValue)
|
||||
{
|
||||
if (newValue == null)
|
||||
{
|
||||
newValue = oldValue;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
_adsManager.WriteValue(InstancePath, newValue);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
newValue = oldValue;
|
||||
Debug.WriteLine("Value {0} could not be written to {1}", newValue, InstancePath);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public partial class SettingsPageVM : ObservableObject, IDisposable
|
||||
{
|
||||
public ObservableCollection<SettingsEntry> RootItem { get; private set; } = [];
|
||||
|
||||
private readonly IAdsManager _adsManager;
|
||||
|
||||
private readonly string _variableName;
|
||||
|
||||
public SettingsPageVM(IAdsManager adsManager, string variableName)
|
||||
{
|
||||
_adsManager = adsManager;
|
||||
_variableName = variableName;
|
||||
|
||||
_adsManager.Register(_variableName, ConfigChangedEvent);
|
||||
}
|
||||
|
||||
private void ConfigChangedEvent(object? sender, ValueChangedEventArgs e)
|
||||
{
|
||||
App.Current.Invoke(CreateSettingsTree);
|
||||
}
|
||||
|
||||
private void CreateSettingsTree()
|
||||
{
|
||||
ISymbolLoader? symbolLoader = _adsManager.GetSymbolLoader();
|
||||
|
||||
if (symbolLoader == null)
|
||||
return;
|
||||
|
||||
Symbol configSymbol = (Symbol)symbolLoader.Symbols[_variableName];
|
||||
SettingsEntry entry = GetSymbol(configSymbol);
|
||||
RootItem.Add(entry);
|
||||
}
|
||||
|
||||
private SettingsEntry GetSymbol(Symbol symbol)
|
||||
{
|
||||
// Create Symbol
|
||||
SettingsEntry entry = new(_adsManager)
|
||||
{
|
||||
Name = symbol.InstanceName,
|
||||
InstancePath = symbol.InstancePath,
|
||||
DataType = symbol.DataType?.Name
|
||||
};
|
||||
|
||||
// Check if symbol has sub symbols
|
||||
if (!symbol.IsPrimitiveType)
|
||||
{
|
||||
foreach (Symbol subSymbol in symbol.SubSymbols.Cast<Symbol>())
|
||||
{
|
||||
entry.SubEntries.Add(GetSymbol(subSymbol));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
entry.Visibility = Visibility.Visible;
|
||||
|
||||
entry.Value = symbol.ReadValue();
|
||||
}
|
||||
|
||||
return entry;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
_adsManager?.Deregister(_variableName, ConfigChangedEvent);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user