Hallo
Ich hatte Prism mehrmal initialisiert. Deswegen ging es nicht.
RemiSearchViewModel:
private readonly IEventAggregator _eventAggregator;
public RemiSearchViewModel()
{
this._eventAggregator = new EventAggregator();
this.ScanClickCommand = new DelegateCommand
(
(o) => Shipment != null,
(o) => { ScanCommand(o); }
);
this.NameClickCommand = new DelegateCommand
(
(o) => Shipment != null,
(o) => { NameCommand(o); }
);
}
public partial class DifferentMarketplacesView : Window
{
private IEventAggregator eventAggregator;
public DifferentMarketplacesView(IEventAggregator eventAggregator)
{
InitializeComponent();
this.DataContext = new DifferentMarketplacesViewModel(eventAggregator);
}
}
public DifferentMarketplacesViewModel(IEventAggregator eventAggregator)
{
_eventAggregator = eventAggregator;
_eventAggregator.GetEvent<DataUpdatedEvent>().Subscribe(OnDataUpdated);
this.MenuClickCommand = new DelegateCommand
(
(o) => ShipmentReturn != null,
(o) => { MenuCommand(); }
);
this.PrintClickCommand = new DelegateCommand
(
(o) => ShipmentReturn != null,
(o) => { PrintCommand(); }
);
this.ArticleClickCommand = new DelegateCommand
(
(o) => ShipmentReturn != null,
(o) => { ArticleCommand(o); }
);
this.FocusClickCommand = new DelegateCommand
(
(o) => ShipmentReturn != null,
(o) => { FocusCommand(o); }
);
articleInfo = mentionRepository.GetArticleInfo();
TextBoxOrderFocus = true;
}
private void OnDataUpdated(HouseShipmentResults updatedData)
{
User = updatedData.Worker;
ShipmentReturn.Add(updatedData);
countToPrint = (int)ShipmentReturn.Sum(x => Convert.ToInt16(x.CustomArticleCount));
}
Hallo
Ich habe eine View wo nach Daten gesucht wird. Aus der View soll am anfang eine ander View geöffnet (nur ein mal) werden und über
_eventAggregator.GetEvent<DataUpdatedEvent>().Publish(value);
eine Daten Klasse übermittelt werden.
Wenn andere Daten gesucht werden, soll dann nur der _eventAggregator.GetEvent<DataUpdatedEvent>().Publish(value);
gestartet werden und denn Datensatz an das Datagrid übermittelt.
Leider klappte es nicht. Was mache ich Falsch ? Oder wie kann man das besser machen ?
Danke für die Hilfe schon mal.
public partial class RemiSearchView : Window
{
private IEventAggregator eventAggregator;
RemiSearchViewModel remiSearchViewModel = new RemiSearchViewModel();
public RemiSearchView(string user)
{
InitializeComponent();
this.eventAggregator = new EventAggregator();
this.DataContext = new RemiSearchViewModel(eventAggregator);
remiSearchViewModel.InitializeData(user);
}
}
RemiSearchViewModel:
private readonly IEventAggregator _eventAggregator;
public RemiSearchViewModel(IEventAggregator eventAggregator)
{
_eventAggregator = eventAggregator;
this.ScanClickCommand = new DelegateCommand
(
(o) => Shipment != null,
(o) => { ScanCommand(o); }
);
this.NameClickCommand = new DelegateCommand
(
(o) => Shipment != null,
(o) => { NameCommand(o); }
);
}
Denn nächsten schritt lass ich aus.
private void OpenViewRemi(HouseShipmentResults value)
{
if(count == 0)
{
DifferentMarketplacesView differentMarketplacesView = new DifferentMarketplacesView();
differentMarketplacesView.Show();
_eventAggregator.GetEvent<DataUpdatedEvent>().Publish(value);
count++;
}
else
{
_eventAggregator.GetEvent<DataUpdatedEvent>().Publish(value);
}
}
public partial class DifferentMarketplacesView : Window
{
private IEventAggregator eventAggregator;
public DifferentMarketplacesView()
{
InitializeComponent();
this.eventAggregator = new EventAggregator();
this.DataContext = new DifferentMarketplacesViewModel(eventAggregator);
}
}
public DifferentMarketplacesViewModel(IEventAggregator eventAggregator)
{
_eventAggregator = eventAggregator;
_eventAggregator.GetEvent<DataUpdatedEvent>().Subscribe(OnDataUpdated);
this.MenuClickCommand = new DelegateCommand
(
(o) => ShipmentReturn != null,
(o) => { MenuCommand(); }
);
this.PrintClickCommand = new DelegateCommand
(
(o) => ShipmentReturn != null,
(o) => { PrintCommand(); }
);
this.ArticleClickCommand = new DelegateCommand
(
(o) => ShipmentReturn != null,
(o) => { ArticleCommand(o); }
);
this.FocusClickCommand = new DelegateCommand
(
(o) => ShipmentReturn != null,
(o) => { FocusCommand(o); }
);
articleInfo = mentionRepository.GetArticleInfo();
TextBoxOrderFocus = true;
}
OnDataUpdated wird nicht aufgerufen.
private void OnDataUpdated(HouseShipmentResults updatedData)
{
User = updatedData.Worker;
ShipmentReturn.Add(updatedData);
countToPrint = (int)ShipmentReturn.Sum(x => Convert.ToInt16(x.CustomArticleCount));
}
Hallo
Ich habe eine spezielle Aufgabe bekomme, wo ich nicht wie das überhaupt Funktionieren soll. Wäre schön, wenn jemand eine Idee oder mir die Richtung zeige wie das machbar ist.
also es soll eine Liste erstellt werden, wo verschiedene Einträge untereinander für ein Artikel stehen soll.
Diese soll dann per Excel da genauso Exportiert werden. Ich habe das so noch nie gemacht, deswegen bräuchte ich da etwas Hilfe.
Muster als Bild.
Danke schon mal im vorraus.
Hi
Danke für alles.
Ich hätte da nochmal eine Frage. Ich möchte zusätzlich ein neues Windows öfnen. Wie würde das Funktionieren. Habe jetzt echt einiges ausprobiert mit Async etc...
Hat hier jemand eine Idee ??? Die Seite wird aufgerufen nur der Spinner Funktioniert so nicht.
Jetzt verstehe ich, was du mit VisibilityBorder und Spin erreichen möchtest - du möchtest diese temporär ausblenden, während der Datenbank-Abfrage. So funktioniert das aber nicht, da die Änderungen erst erfolgen, wenn die gesamte Methode abgearbeitet ist (und die Windows- bzw. WPF-Nachrichtenschleife wieder ein Update der UI anstößt - s.a. [FAQ] Warum blockiert mein GUI?).
Hierfür benötigst du dann asynchrone Programmierung (async/ await/ Task<T>), um auf die Datenbankabfrage zu warten.
Model
public MainWindowModel()
{
this.LoginCommand = new ViewModelCommand(ExecuteLoginCommand, CanExecuteLoginCommand);
Username = System.Security.Principal.WindowsIdentity.GetCurrent().Name;
}
private bool CanExecuteLoginCommand(object obj)
{
bool validData;
if (string.IsNullOrWhiteSpace(Username) || Username.Length < 3 ||
Password == null || Password.Length < 3)
validData = false;
else
validData = true;
return validData;
}
private async void ExecuteLoginCommand(object obj)
{
// Set up the loading spinner on the UI thread
ShowLoadingSpinner();
// Show the new window asynchronously
await Application.Current.Dispatcher.InvokeAsync(() =>
{
var isValidUser = AuthenticateUser(new NetworkCredential(Username, Password));
if (isValidUser)
{
Thread.CurrentPrincipal = new GenericPrincipal(
new GenericIdentity(Username), null);
MainDispoView mainDispoView = new MainDispoView();
mainDispoView.Show();
Application.Current.MainWindow.Close();
}
else
{
ErrorMessage = "* Invalid username or password";
}
});
CloseLoadingSpinner();
}
private void CloseLoadingSpinner()
{
// Update UI elements related to the loading spinner using the Dispatcher
Application.Current.Dispatcher.Invoke(() =>
{
// Show loading spinner logic (e.g., set a property bound to visibility)
// You can define a property in your ViewModel to control the visibility of the spinner.
IsViewVisible = false;
IsLoading = false;
});
}
private void ShowLoadingSpinner()
{
// Update UI elements related to the loading spinner using the Dispatcher
Application.Current.Dispatcher.Invoke(() =>
{
// Close loading spinner logic (e.g., set a property bound to visibility)
IsLoading = true;
IsViewVisible = true;
});
}
So Funktioniert jetzt, danke nochmal.
private async void IsSelectCommand(object o)
{
var selectedRow = o as AmazonKwEvaluationList;
if (selectedRow != null)
{
VisibilityBorder = true;
Spin = true;
someTask = Task.Run(new Action(async () =>
{
VkArtikel = (selectedRow.week_cur + selectedRow.week_a + selectedRow.week_b + selectedRow.week_c + selectedRow.week_d + selectedRow.week_e + selectedRow.week_f + selectedRow.week_g + selectedRow.week_h + selectedRow.week_i + selectedRow.week_j + selectedRow.week_k + selectedRow.week_l + selectedRow.week_m + selectedRow.week_n + selectedRow.week_o + selectedRow.week_p + selectedRow.week_q + selectedRow.week_r + selectedRow.week_s + selectedRow.week_t + selectedRow.week_u + selectedRow.week_v + selectedRow.week_w + selectedRow.week_x + selectedRow.week_y + selectedRow.week_z
+ selectedRow.week_aa + selectedRow.week_ab + selectedRow.week_ac + selectedRow.week_ad + selectedRow.week_ae + selectedRow.week_af + selectedRow.week_ag + selectedRow.week_ah + selectedRow.week_ai + selectedRow.week_aj + selectedRow.week_ak + selectedRow.week_al + selectedRow.week_am + selectedRow.week_an + selectedRow.week_ao + selectedRow.week_ap + selectedRow.week_aq + selectedRow.week_ar + selectedRow.week_as + selectedRow.week_at + selectedRow.week_au + selectedRow.week_av + selectedRow.week_aw + selectedRow.week_ax + selectedRow.week_ay).ToString() + " St.";
UmArtikel = (selectedRow.price_cur + selectedRow.price_a + selectedRow.price_b + selectedRow.price_c + selectedRow.price_d + selectedRow.price_e + selectedRow.price_f + selectedRow.price_g + selectedRow.price_h + selectedRow.price_i + selectedRow.price_j + selectedRow.price_k + selectedRow.price_l + selectedRow.price_m + selectedRow.price_n + selectedRow.price_o + selectedRow.price_p + selectedRow.price_q + selectedRow.price_r + selectedRow.price_s + selectedRow.price_t + selectedRow.price_u + selectedRow.price_v + selectedRow.price_w + selectedRow.price_x + selectedRow.price_y + selectedRow.price_z
+ selectedRow.price_aa + selectedRow.price_ab + selectedRow.price_ac + selectedRow.price_ad + selectedRow.price_ae + selectedRow.price_af + selectedRow.price_ag + selectedRow.price_ah + selectedRow.price_ai + selectedRow.price_aj + selectedRow.price_ak + selectedRow.price_al + selectedRow.price_am + selectedRow.price_an + selectedRow.price_ao + selectedRow.price_ap + selectedRow.price_aq + selectedRow.price_ar + selectedRow.price_as + selectedRow.price_at + selectedRow.price_au + selectedRow.price_av + selectedRow.price_aw + selectedRow.price_ax + selectedRow.price_ay).ToString("#,#.00", CultureInfo.InvariantCulture) + " €";
MaArtikel = (selectedRow.margin_cur + selectedRow.margin_a + selectedRow.margin_b + selectedRow.margin_c + selectedRow.margin_d + selectedRow.margin_e + selectedRow.margin_f + selectedRow.margin_g + selectedRow.margin_h + selectedRow.margin_i + selectedRow.margin_j + selectedRow.margin_k + selectedRow.margin_l + selectedRow.margin_m + selectedRow.margin_n + selectedRow.margin_o + selectedRow.margin_p + selectedRow.margin_q + selectedRow.margin_r + selectedRow.margin_s + selectedRow.margin_t + selectedRow.margin_u + selectedRow.margin_v + selectedRow.margin_w + selectedRow.margin_x + selectedRow.margin_y + selectedRow.margin_z
+ selectedRow.margin_aa + selectedRow.margin_ab + selectedRow.margin_ac + selectedRow.margin_ad + selectedRow.margin_ae + selectedRow.margin_af + selectedRow.margin_ag + selectedRow.margin_ah + selectedRow.margin_ai + selectedRow.margin_aj + selectedRow.margin_ak + selectedRow.margin_al + selectedRow.margin_am + selectedRow.margin_an + selectedRow.margin_ao + selectedRow.margin_ap + selectedRow.margin_aq + selectedRow.margin_ar + selectedRow.margin_as + selectedRow.margin_at + selectedRow.margin_au + selectedRow.margin_av + selectedRow.margin_aw + selectedRow.margin_ax + selectedRow.margin_ay).ToString("#,#.00", CultureInfo.InvariantCulture) + " €";
QuarterArticle = await listPreparationRepository.GetQuarterArticle(selectedRow.Article, platform, marketplace, DateTime.Now.Year.ToString());
}));
await someTask;
VisibilityBorder = false;
Spin = false;
}
else
{
QuarterArticle = null;
VkArtikel = "";
UmArtikel = "";
MaArtikel = "";
}
}
Deine Frage bezüglich des Datensatz, verstehe ich jetzt nicht genau was du meinst ?
Das ist ja eine Klasse wo ich unterschiedliche Berechnungen durchführen muss. Du meinst es ist einfacher mit einem Array. Wie genau ?
Ahhhh Danke alles klar, das weiß ich ja auch eigentlich. Ändere ich jetzt.
Deinen zweiten vorschlag werde ich mir nächte Woche zur brust nehmen. Danke
Converter
public class BoolToVisConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
try
{
var boolValue = (bool)value;
if (boolValue)
return Visibility.Visible;
else
return Visibility.Collapsed;
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
try
{
if (((Visibility)value).Equals(Visibility.Collapsed))
return false;
else
return true;
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
}
}
Du meinst das. Das ist ein Datensatz einer Liste.
VkArtikel = (selectedRow.week_cur + selectedRow.week_a + selectedRow.week_b + selectedRow.week_c + selectedRow.week_d + selectedRow.week_e + selectedRow.week_f + selectedRow.week_g + selectedRow.week_h + selectedRow.week_i + selectedRow.week_j + selectedRow.week_k + selectedRow.week_l + selectedRow.week_m + selectedRow.week_n + selectedRow.week_o + selectedRow.week_p + selectedRow.week_q + selectedRow.week_r + selectedRow.week_s + selectedRow.week_t + selectedRow.week_u + selectedRow.week_v + selectedRow.week_w + selectedRow.week_x + selectedRow.week_y + selectedRow.week_z
+ selectedRow.week_aa + selectedRow.week_ab + selectedRow.week_ac + selectedRow.week_ad + selectedRow.week_ae + selectedRow.week_af + selectedRow.week_ag + selectedRow.week_ah + selectedRow.week_ai + selectedRow.week_aj + selectedRow.week_ak + selectedRow.week_al + selectedRow.week_am + selectedRow.week_an + selectedRow.week_ao + selectedRow.week_ap + selectedRow.week_aq + selectedRow.week_ar + selectedRow.week_as + selectedRow.week_at + selectedRow.week_au + selectedRow.week_av + selectedRow.week_aw + selectedRow.week_ax + selectedRow.week_ay).ToString() + " St.";
UmArtikel = (selectedRow.price_cur + selectedRow.price_a + selectedRow.price_b + selectedRow.price_c + selectedRow.price_d + selectedRow.price_e + selectedRow.price_f + selectedRow.price_g + selectedRow.price_h + selectedRow.price_i + selectedRow.price_j + selectedRow.price_k + selectedRow.price_l + selectedRow.price_m + selectedRow.price_n + selectedRow.price_o + selectedRow.price_p + selectedRow.price_q + selectedRow.price_r + selectedRow.price_s + selectedRow.price_t + selectedRow.price_u + selectedRow.price_v + selectedRow.price_w + selectedRow.price_x + selectedRow.price_y + selectedRow.price_z
+ selectedRow.price_aa + selectedRow.price_ab + selectedRow.price_ac + selectedRow.price_ad + selectedRow.price_ae + selectedRow.price_af + selectedRow.price_ag + selectedRow.price_ah + selectedRow.price_ai + selectedRow.price_aj + selectedRow.price_ak + selectedRow.price_al + selectedRow.price_am + selectedRow.price_an + selectedRow.price_ao + selectedRow.price_ap + selectedRow.price_aq + selectedRow.price_ar + selectedRow.price_as + selectedRow.price_at + selectedRow.price_au + selectedRow.price_av + selectedRow.price_aw + selectedRow.price_ax + selectedRow.price_ay).ToString("#,#.00", CultureInfo.InvariantCulture) + " €";
MaArtikel = (selectedRow.margin_cur + selectedRow.margin_a + selectedRow.margin_b + selectedRow.margin_c + selectedRow.margin_d + selectedRow.margin_e + selectedRow.margin_f + selectedRow.margin_g + selectedRow.margin_h + selectedRow.margin_i + selectedRow.margin_j + selectedRow.margin_k + selectedRow.margin_l + selectedRow.margin_m + selectedRow.margin_n + selectedRow.margin_o + selectedRow.margin_p + selectedRow.margin_q + selectedRow.margin_r + selectedRow.margin_s + selectedRow.margin_t + selectedRow.margin_u + selectedRow.margin_v + selectedRow.margin_w + selectedRow.margin_x + selectedRow.margin_y + selectedRow.margin_z
+ selectedRow.margin_aa + selectedRow.margin_ab + selectedRow.margin_ac + selectedRow.margin_ad + selectedRow.margin_ae + selectedRow.margin_af + selectedRow.margin_ag + selectedRow.margin_ah + selectedRow.margin_ai + selectedRow.margin_aj + selectedRow.margin_ak + selectedRow.margin_al + selectedRow.margin_am + selectedRow.margin_an + selectedRow.margin_ao + selectedRow.margin_ap + selectedRow.margin_aq + selectedRow.margin_ar + selectedRow.margin_as + selectedRow.margin_at + selectedRow.margin_au + selectedRow.margin_av + selectedRow.margin_aw + selectedRow.margin_ax + selectedRow.margin_ay).ToString("#,#.00", CultureInfo.InvariantCulture) + " €";
Ich habe jetzt einiges hin und her probiert aber ich bekomme den Converter nicht zum laufen ???
Beim debug merke ich auch das der ConvertBack, nicht angesprochen wird.
private void CheckBoxCommand(object o)
{
VisibilityBorder = true;
Spin = true;
platform = o as string;
marketplace = "";
QuarterArticle = null;
if (platform.Contains('.'))
{
marketplace = platform;
platform = "";
}
PlatformKw = listPreparationRepository.GetVendorAmazonDataKW(platform, marketplace);
Quarter = listPreparationRepository.GetQuarter(platform, marketplace, DateTime.Now.Year.ToString());
FilterCollection = CollectionViewSource.GetDefaultView(PlatformKw);
//HeaderGroupBox = "Artikel (" + PlatformKw.Count.ToString() + ")";
GetHeaderGroupBoxCount();
Spin = true;
VisibilityBorder = true;
};
Wenn ich den teil zwei mal auf true setze geht es aber dann ist die Abfrage schon durch.
Spin = false;
VisibilityBorder = false;
Was genau meinst du mit dem Satz ?
Und beim Datenmodell meine ich: warum hast du dort kein Array (bzw. List<...>), anstatt den zig Einzeleigenschaften?
Jo danke, ist ja einfach 😃
Eine letzte Frage hätte ich aber noch. Mein Visibility Binding Funktioniert nicht. Der soll den Spinner auslössen.
<Border
Name="OverlayDataGrid"
Grid.Row="0"
Grid.RowSpan="5"
Panel.ZIndex="1"
Background="LightGray"
Opacity="0.7"
Visibility="{Binding VisibilityBorder, Converter={StaticResource booleanVisibilityConverter}}">
<fa5:ImageAwesome
Name="OverlayDataGridSpinner"
Width="128"
Height="128"
Icon="Solid_Robot"
Spin="{Binding Spin}"
SpinDuration="15"/>
</Border>
Model
private bool _visibilityBorder = false;
public bool VisibilityBorder
{
get => _visibilityBorder;
set
{
if (_visibilityBorder != value)
{
_visibilityBorder = value;
this.RaisePropertyChanged();
}
}
}
private bool _spin;
public bool Spin
{
get => _spin;
set
{
if (_spin != value)
{
_spin = value;
this.RaisePropertyChanged();
}
}
}
private void CheckBoxCommand(object o)
{
VisibilityBorder = true;
Spin = true;
platform = o as string;
marketplace = "";
QuarterArticle = null;
if (platform.Contains('.'))
{
marketplace = platform;
platform = "";
}
PlatformKw = listPreparationRepository.GetVendorAmazonDataKW(platform, marketplace);
Quarter = listPreparationRepository.GetQuarter(platform, marketplace, DateTime.Now.Year.ToString());
FilterCollection = CollectionViewSource.GetDefaultView(PlatformKw);
//HeaderGroupBox = "Artikel (" + PlatformKw.Count.ToString() + ")";
GetHeaderGroupBoxCount();
Spin = false;
VisibilityBorder = false;
}
Converter
public class BoolToVisConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
try
{
if ((bool)value)
{
return Visibility.Visible;
}
else
{
return Visibility.Collapsed;
}
}
catch
{
return Visibility.Collapsed;
}
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
try
{
if ((bool)value)
{
return Visibility.Visible;
}
}
catch { }
return Visibility.Collapsed;
}
}
Wenn der VisibilityBorder auf true gesetzt wird gibt es keine reaxtion. Der Converter wird aber angesprochen.
Wenn ich den VisibilityBorder statt auf false auf true setze, funktioniert es nach der Abfrage.
Wo könnte hier das Problem liegen ???