当 ScottPlot WPF 控件放置在数据模板内并用于绘图时,不会呈现任何内容。我很困惑为什么以下代码不起作用:
这是我的看法:
<Window x:Class="Client.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:Client"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800">
<Window.Resources>
<DataTemplate x:Key="DataPlotTemplate">
<StackPanel>
<TextBlock Text="{Binding Title}"/>
<WpfPlot MinHeight="300" MinWidth="300" Content="{Binding DataPlot}"/>
<TextBlock Text="{Binding Description}"/>
</StackPanel>
</DataTemplate>
</Window.Resources>
<Grid>
<StackPanel>
<ContentControl Content="{Binding DataPlotVm0}"
ContentTemplate="{StaticResource DataPlotTemplate}"/>
<ContentControl Content="{Binding DataPlotVm1}"
ContentTemplate="{StaticResource DataPlotTemplate}"/>
</StackPanel>
</Grid>
</Window>
这是我的视图模型:
public class DataPlotViewModel : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
protected void OnPropertyChange(string propertyName)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
private string title = "";
public string Title
{
get { return title; }
set
{
title = value;
OnPropertyChange("Title");
}
}
public ScottPlot.WpfPlot DataPlot { get; set; } = new ScottPlot.WpfPlot();
private string description = "";
public string Description
{
get { return description; }
set
{
description = value;
OnPropertyChange("Description");
}
}
}
当DataPlot
视图模型用于绘图时,什么都不会出现。