我有一个UserControl( FahrtControl.xaml) 和一个ListView. 这UserControl势必给ItemsControl我MainWindow.xaml。该MainWindow有自己的视图模型和FahrtControl拥有自己的视图模型。我现在想的背景结合Listview项目的Brush中的视图模型属性FahrtControl。以下是我的代码的相关部分:主窗口.xaml:<Window x:Class="WpfFrontend.Forms.Main.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:WpfFrontend.Forms.Main" xmlns:fahrtControl="clr-namespace:WpfFrontend.Controls.FahrtControl" mc:Ignorable="d"><Window.DataContext> <local:MainViewModel /></Window.DataContext><Window.Resources> <DataTemplate DataType="{x:Type fahrtControl:FahrtControlViewModel}"> <fahrtControl:FahrtControl /> </DataTemplate></Window.Resources><ItemsControl ItemsSource="{Binding Fahrten, UpdateSourceTrigger=PropertyChanged}" />主视图模型.cs:using System;using System.Collections.Generic;using System.Collections.ObjectModel;using System.ComponentModel;using System.Linq;using System.Runtime.CompilerServices;using System.Windows.Controls;using System.Windows.Media;using Backend;using DatabaseCommunication;using WpfFrontend.Annotations;using WpfFrontend.Controls.FahrtControl;namespace WpfFrontend.Forms.Main{ public class MainViewModel : INotifyPropertyChanged { public MainViewModel () { SyncFahrten (); } private void SyncFahrten () { var fahrtenPromise = MainUtility.GetFahrtenToRangeAsync (GlobalProperties.Start, GlobalProperties.Start.AddDays (6)); fahrtenPromise.Task.GetAwaiter ().OnCompleted (() => { AddFahrten (fahrtenPromise.Task.Result); }); }
1 回答
- 1 回答
- 0 关注
- 470 浏览
添加回答
举报
0/150
提交
取消