Skocz do zawartości

[Sfera zdarzeniowa] Własne okna dialogowe

Polecane posty

Czy można prosić, o nakierowanie na jakiś tutorial/dokumentacje, dodawania okien własnych w Sferze zdarzeniowej. Zakładam, że jest to kontrolka użytkownika WPF, ale próbując odtworzyć wasze przykłady i różne informacje z internetu, jakoś nie mogę uzyskać efektu jak w przykładach z NEXO SDK. Będę wdzięczny za każdą pomoc.

Link to postu

W SDK w katalogu Przyklady\SferaZdarzeniowa\ObslugaLogistyki jest dość rozbudowane rozwiązanie, w którym użyte są własne wyskakujące okienka WPFowe. Implementacja tych okien jest w podkatalogu UI, zaś ich użycie w klasach AutomatycznaZmianaSamochoduDostawczegoPlugin oraz AutomatycznaRezerwacjaSamochoduDostawczegoPlugin w podkatalogu Automaty. Jeśli chciałby Pan sprawdzić jak całe rozwiązanie działa w praktyce to została również przygotowana instrukcja wdrożeniowa gdyż do działania wymaga ono odpowiedniej konfiguracji podmiotu w szczególności w kontekście pól własnych (dokumentacja.pdf).

Link to postu

Ok, wstępnie jakieś tam okienko utworzyłem i pokazałem, i dotarłem do momentu, że chciałem je zamknąć i psuję Subiekta, bo coś źle inicjuje. Nie ukrywam, że chcę stworzyć na początek coś prostego - wasz przykład jest dosyć mocno w tle rozbudowany, co oczywiście jest dobre, ale trudniej się rozgryza, jak się nie ma doświadczenia w tej części C# :)

Proszę nie zwracać uwagi na nazwy funkcji/zmiennych, to totalnie na próbę, a przez wasze nazywanie po polsku, zawsze dostaje dwubiegunówki :D

Więc, dodałem Sobie Kontrolke użytkownika WPF, którą podmodyfikowamłem w XAML, na tym Windows - nie znalazłem na liście nowych elementów, bezpośrednio okna, więc może tutaj już namieszałem:

<Window x:Class="UItest.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" 
             xmlns:local="clr-namespace:UItest"
             Title="Testowe okno dialogowe"
        WindowStartupLocation="CenterOwner"
        ResizeMode="CanResize"
        ShowInTaskbar="False"
        Topmost="True"
             mc:Ignorable="d" 
             Width="410" Height="200">
    <DockPanel LastChildFill="True">
        <Button     IsDefault="True"
                    Content="Zamknij"
                    Width="75"
                    Height="30"
                    IsCancel="False"
                    Margin="0,5,5,5"
                    Click="Zamknij"
                    DockPanel.Dock="Bottom"
                    HorizontalAlignment="Right"/>
        <StackPanel Orientation="Vertical">
            <TextBlock Margin="5,5,0,0" TextWrapping="WrapWithOverflow">
            <Run Text="Tutaj jest nazwa pola dialogowego:"/>
            </TextBlock>
            <ComboBox   ItemsSource="{Binding Path=ListaWartosci, Mode=OneTime}"
                    Margin="5 10 5 0"
                    SelectedValue="{Binding Path=Wybrane, Mode=TwoWay}"
                    DisplayMemberPath="Wartosc"/>
        </StackPanel>
    </DockPanel>
</Window>

No i mam cs od okienka, który dostosowałem do Window i dodałem Sobie póki co reakcję na przycisk Zamknij

namespace UItest
{
    /// <summary>
    /// Logika interakcji dla klasy UserControl1.xaml
    /// </summary>
    public partial class UserControl1 : Window
    {
        public UserControl1()
        {
            InitializeComponent();
        }
        private void Zamknij(object sender, RoutedEventArgs e)
        {
            DialogResult = true;
            Close();
        }
    }
}

No i mam ten DialogResult, który jest w funkcji Zamknij, który według dokumentacji na Microsoft: https://learn.microsoft.com/en-us/dotnet/api/system.windows.window.dialogresult?view=windowsdesktop-7.0

Klikam zamknij, okno się nie zamyka, a Subiekt wyrzuca raport błędu:

System.InvalidOperationException: DialogResult można ustawić tylko po utworzeniu elementu typu Window i jego wyświetleniu jako okna dialogowego.
   w System.Windows.Window.set_DialogResult(Nullable`1 value)
   w UItest.UserControl1.Zamknij(Object sender, RoutedEventArgs e)
   w System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
   w System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
   w System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
   w System.Windows.UIElement.RaiseEvent(RoutedEventArgs e)
   w System.Windows.Controls.Primitives.ButtonBase.OnClick()
   w System.Windows.Controls.Button.OnClick()
   w System.Windows.Controls.Primitives.ButtonBase.OnMouseLeftButtonUp(MouseButtonEventArgs e)
   w System.Windows.UIElement.OnMouseLeftButtonUpThunk(Object sender, MouseButtonEventArgs e)
   w System.Windows.Input.MouseButtonEventArgs.InvokeEventHandler(Delegate genericHandler, Object genericTarget)
   w System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
   w System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
   w System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
   w System.Windows.UIElement.ReRaiseEventAs(DependencyObject sender, RoutedEventArgs args, RoutedEvent newEvent)
   w System.Windows.UIElement.OnMouseUpThunk(Object sender, MouseButtonEventArgs e)
   w System.Windows.Input.MouseButtonEventArgs.InvokeEventHandler(Delegate genericHandler, Object genericTarget)
   w System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
   w System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
   w System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
   w System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
   w System.Windows.UIElement.RaiseTrustedEvent(RoutedEventArgs args)
   w System.Windows.UIElement.RaiseEvent(RoutedEventArgs args, Boolean trusted)
   w System.Windows.Input.InputManager.ProcessStagingArea()
   w System.Windows.Input.InputManager.ProcessInput(InputEventArgs input)
   w System.Windows.Input.InputProviderSite.ReportInput(InputReport inputReport)
   w System.Windows.Interop.HwndMouseInputProvider.ReportInput(IntPtr hwnd, InputMode mode, Int32 timestamp, RawMouseActions actions, Int32 x, Int32 y, Int32 wheel)
   w System.Windows.Interop.HwndMouseInputProvider.FilterMessage(IntPtr hwnd, WindowMessage msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
   w System.Windows.Interop.HwndSource.InputFilterMessage(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
   w MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
   w MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
   w System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
   w System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)

EnvironmentStackTrace:
   w System.Environment.GetStackTrace(Exception e, Boolean needFileInfo)
   w System.Environment.get_StackTrace()
   w InsERT.Mox.Helpers.Ferf.AnalyzedException..ctor(Exception exception)
   w InsERT.Mox.UIFramework.ErrorContext..ctor(Exception exception, String dumpFilePath, Stream screenCapture)
   w InsERT.Moria.Startup.UI.NerfSupport.ShowFerfWindow(Exception exception, String dumpFile, Boolean newThread)
   w InsERT.Moria.Startup.UI.NerfSupport.HandleUsingFerf(Exception exception)
   w InsERT.Moria.Startup.UI.NerfSupport.ProcessUnhandledException(Exception exception)
   w InsERT.Moria.Startup.UI.NerfSupport.Dispatcher_UnhandledExceptionFilter(Object sender, DispatcherUnhandledExceptionFilterEventArgs e)
   w System.Windows.Threading.Dispatcher.ExceptionFilter(Exception e)
   w System.Windows.Threading.Dispatcher.ExceptionFilterStatic(Object source, Exception e)
   w System.Windows.Threading.ExceptionWrapper.FilterException(Object source, Exception e)
   w System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
   w System.Windows.Window.set_DialogResult(Nullable`1 value)
   w UItest.UserControl1.Zamknij(Object sender, RoutedEventArgs e)
   w System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
   w System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
   w System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
   w System.Windows.UIElement.RaiseEvent(RoutedEventArgs e)
   w System.Windows.Controls.Primitives.ButtonBase.OnClick()
   w System.Windows.Controls.Button.OnClick()
   w System.Windows.Controls.Primitives.ButtonBase.OnMouseLeftButtonUp(MouseButtonEventArgs e)
   w System.Windows.UIElement.OnMouseLeftButtonUpThunk(Object sender, MouseButtonEventArgs e)
   w System.Windows.Input.MouseButtonEventArgs.InvokeEventHandler(Delegate genericHandler, Object genericTarget)
   w System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
   w System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
   w System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
   w System.Windows.UIElement.ReRaiseEventAs(DependencyObject sender, RoutedEventArgs args, RoutedEvent newEvent)
   w System.Windows.UIElement.OnMouseUpThunk(Object sender, MouseButtonEventArgs e)
   w System.Windows.Input.MouseButtonEventArgs.InvokeEventHandler(Delegate genericHandler, Object genericTarget)
   w System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
   w System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
   w System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
   w System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
   w System.Windows.UIElement.RaiseTrustedEvent(RoutedEventArgs args)
   w System.Windows.UIElement.RaiseEvent(RoutedEventArgs args, Boolean trusted)
   w System.Windows.Input.InputManager.ProcessStagingArea()
   w System.Windows.Input.InputManager.ProcessInput(InputEventArgs input)
   w System.Windows.Input.InputProviderSite.ReportInput(InputReport inputReport)
   w System.Windows.Interop.HwndMouseInputProvider.ReportInput(IntPtr hwnd, InputMode mode, Int32 timestamp, RawMouseActions actions, Int32 x, Int32 y, Int32 wheel)
   w System.Windows.Interop.HwndMouseInputProvider.FilterMessage(IntPtr hwnd, WindowMessage msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
   w System.Windows.Interop.HwndSource.InputFilterMessage(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
   w MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
   w MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
   w System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
   w System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
   w System.Windows.Threading.Dispatcher.LegacyInvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs)
   w MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
   w MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg)
   w System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)
   w System.Windows.Threading.Dispatcher.PushFrame(DispatcherFrame frame)
   w System.Windows.Window.ShowHelper(Object booleanBox)
   w System.Windows.Window.Show()
   w System.Windows.Window.ShowDialog()
   w InsERT.Moria.Startup.UI.NexoAppBase.Go()
   w InsERT.Moria.Subiekt.SubiektApp.Main(String[] args)

Dodam jeszcze, że ja okno dialogowe otwieram tak, a u was nie zauważyłem nigdzie funkcji Show(), ale macie te pośredniczące funkcje, więc może wyszukiwarka zawiodła:

        public override void PoInicjalizacjiObiektu(IKontekstInicjalizacjiObiektu<IZamowienieOdKlienta> kontekst)
        {
            UserControl1 okienko = new UserControl1();
            okienko.Show();
            

        }

 

Link to postu
W dniu 14.08.2023 o 22:08, Radomił Ząbik napisał:
DialogResult można ustawić tylko po utworzeniu elementu typu Window i jego wyświetleniu jako okna dialogowego.

Wydaje się, że ten komunikat mówi wszystko - w zasadzie jego druga część. Pan wyświetla okno metodą Show więc u Pana NIE jest to okno dialogowe. Należy skorzystać z metody ShowDialog(). W przykładach pokazywanie okien dialogowych jest w klasach $\SferaZdarzeniowa\ObslugaLogistyki\Automaty\AutomatycznaRezerwacjaSamochoduDostawczegoPlugin.cs -> ObsluzKomunikat(string) oraz $\SferaZdarzeniowa\ObslugaLogistyki\Automaty\AutomatycznaZmianaSamochoduDostawczegoPlugin.cs --> PoZmianieWlasciwosciObiektu(...).

Link to postu
×
×
  • Dodaj nową pozycję...