Hallo zusammen :D,
ich möchte gern zwei Control von selbem Typ von einem zweiten Fenster aus Steuern.
Spoiler anzeigen
Was ich bis jetzt herausgefunden habe ist, das ich den DataContext vom Window1 an Window2 geben muss.
Mein Hauptproblem ist das die Werte nicht ausgetauscht werden zwischen den Fenster und dem Controls.
Aber wie komme ich and die Property meines jeweiligen Controls?
Gib es sogar einen besseren Ansatz?
Mein Aufbau sieht momentan wie folgt aus:
CamController
Spoiler anzeigen
Window1 - MainWindow.xaml
Window2 - Setting.xaml
Spoiler anzeigen
MfG
Facebamm :D
Edit: Window1 Copy/Past fix
ich möchte gern zwei Control von selbem Typ von einem zweiten Fenster aus Steuern.
HTML-Quellcode
- --------------------------------- --------------------------------
- |Window1 _ □ x | |Window2 _ □ x |
- --------------------------------- --------------------------------
- | |------------| |------------| | | ImageLeft: | ImageRight |
- | | | | | | | Filter: | Filter: |
- | | Image1 | | Image2 | | . -> | |TextBox | | |TextBox | | <- .
- | | | | | | | | Filter2: | Filter2: | |
- | |------------| |------------| | . -> | |TextBox | | |TextBox | | <- .
- --------------------------------- | ................................ |
- ^ ^-------------- | ---------------------------------------.
- | |
- . ------------------------------.
Was ich bis jetzt herausgefunden habe ist, das ich den DataContext vom Window1 an Window2 geben muss.
Mein Hauptproblem ist das die Werte nicht ausgetauscht werden zwischen den Fenster und dem Controls.
Aber wie komme ich and die Property meines jeweiligen Controls?
Gib es sogar einen besseren Ansatz?
Mein Aufbau sieht momentan wie folgt aus:
CamController
C#-Quellcode
- [Designer("CamController")]
- public class CamController: Image, INotifyPropertyChanged
- {
- public event PropertyChangedEventHandler PropertyChanged;
- ...
- internal int _Threshold1;
- public int Threshold1{
- get => _Threshold1; set {
- if (_Threshold1!= value)
- UpdateWithNotify(ref _Threshold1, value);
- }
- }
- ...
- private void UpdateWithNotify<T>(ref T source, T value, [CallerMemberName] string propertyName = "")
- {
- if (!EqualityComparer<T>.Default.Equals(source, value))
- {
- source = value;
- PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
- //Hier bin ich mir mega unsicher ob es nicht zu komplikationen mit dem 'propertyName' kommt
- }
- }
- }
Window1 - MainWindow.xaml
Window2 - Setting.xaml
XML-Quellcode
- <Window
- ...
- xmlns:local="clr-namespace:OptTwlCtrl"
- xmlns:sys="clr-namespace:System;assembly=mscorlib"
- mc:Ignorable="d">
- <Window.DataContext>
- <local:MainWindow/>
- </Window.DataContext>
- ...
- <TextBox ... Text="{Binding ElementName=CamLeft, Path=Threshold1, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>
- <TextBox ... Text="{Binding ElementName=CamRight, Path=Threshold1, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>
- ...
- </Window>
MfG
Facebamm :D
Edit: Window1 Copy/Past fix
Dieser Beitrag wurde bereits 2 mal editiert, zuletzt von „Facebamm“ ()