繁体   English   中英

WPF DynamicDataDisplay模板轴标签,带有基于值的图标图像

[英]WPF DynamicDataDisplay templating axis labels with icon images based on value

在为WPF搜索打开的图表库时,我找到了DynamicDataDisplay库。

但是我找不到一种方法(可能是因为文档很差)来根据值格式化它们包含图像的轴标签。

为什么我需要这个?

我目前正在编写一个跟踪游戏市场价格(GW2)的工具。

这些价格显示为黄金,白银和铜,我根据铜价得到价格,我希望纵轴显示价格。

所以希望有人知道模拟D3轴标记的方法。

感谢Mikhail Brinchuk指出我正确的方向。 这是我提出的解决方案:

<Window x:Class="ChartTest.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d3="http://research.microsoft.com/DynamicDataDisplay/1.0"
    xmlns:chart="clr-namespace:ChartTest.Chart"
    Title="MainWindow" Height="350" Width="525">
<Window.Resources>
    <chart:MoneyLabelProvider x:Key="MoneyLabelProvider"></chart:MoneyLabelProvider>
</Window.Resources>
<Grid>
    <d3:ChartPlotter x:Name="Plotter">
        <d3:ChartPlotter.VerticalAxis>
            <d3:VerticalIntegerAxis x:Name="Axis" LabelProvider="{StaticResource MoneyLabelProvider}">
            </d3:VerticalIntegerAxis>
         </d3:ChartPlotter.VerticalAxis>

        <d3:ChartPlotter.HorizontalAxis>
            <d3:HorizontalDateTimeAxis x:Name="DateTimeAxis">
            </d3:HorizontalDateTimeAxis>
        </d3:ChartPlotter.HorizontalAxis>
    </d3:ChartPlotter>
</Grid>

public class MoneyLabelProvider : GenericLabelProvider<int>
{
    public override System.Windows.UIElement[] CreateLabels(Microsoft.Research.DynamicDataDisplay.Charts.ITicksInfo<int> ticksInfo)
    {
        var customElements = new UIElement[ticksInfo.Ticks.Length];

        for (int i = 0; i < customElements.Length; i++)
        {
            var mv = new MoneyView(); // View provides the money style format
            var money = new Money(0, 0, ticksInfo.Ticks[i]); // Data class provides the calculation
            mv.DataContext = money; // Bind the data to the view

            customElements[i] = mv;
        }

        return customElements;
    }
}

Axis包含LabelProvider属性。 您可以创建自定义标签提供程序,并在重写方法CreateLabels中创建所需的所有控件。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM