小编Mil*_*leu的帖子

等待数组中的第一个任务以匹配条件

我有一个Task<bool>[] myTasks.第一次Task返回时如何收到通知(等待)true

c# async-await

5
推荐指数
1
解决办法
557
查看次数

将ViewModel传递给UserControl

MySpecialView是一个复杂的图像控件,我想从不同的角度重用它,并ViewModel像本例一样传递它。

MainWindow.xaml

<Window x:Class="YouBug.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:YouBug"
    mc:Ignorable="d"
    DataContext="{Binding MainViewModel}"
    Title="MainWindow" Height="350" Width="525">
<Grid>
    <local:MySpecialView ViewModel="{Binding MySpecialViewModel}"></local:MySpecialView>
</Grid>
Run Code Online (Sandbox Code Playgroud)

主视图模型

    public class MainViewModel
{
    public MySpecialViewModel MySpecialViewModel { get; set; }

    public MainViewModel()
    {
        MySpecialViewModel = new MySpecialViewModel();
        //gets not displayed!
        Task.Run(() => MySpecialViewModel.changeImage(5000, "C:\\Users\\user\\Pictures\\Capture.PNG"));
    }
}
Run Code Online (Sandbox Code Playgroud)

MySpecialView.xaml

<UserControl x:Class="YouBug.MySpecialView"
         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:YouBug"
         mc:Ignorable="d" 
         d:DesignHeight="300" d:DesignWidth="300">
<Grid>
    <Image Source="{Binding ImageSource}" />
</Grid>
Run Code Online (Sandbox Code Playgroud)

MySpecialView.xaml.cs

    public partial class MySpecialView : UserControl
{
    public static readonly DependencyProperty …
Run Code Online (Sandbox Code Playgroud)

c# wpf xaml user-controls mvvm

0
推荐指数
1
解决办法
3176
查看次数

标签 统计

c# ×2

async-await ×1

mvvm ×1

user-controls ×1

wpf ×1

xaml ×1