0

这可能是一个很长的故事,但我真的不知道解决它。

一家公司生产食品、饮料和其他 3 类产品,每个类别下都有多个产品。例如,食品类别有巧克力、饼干等产品;饮料类有奶、茶、可乐等产品;另一类有书籍、时钟等产品。

在某个时期,公司最多生产3种不同品类的产品。例如,公司在一月份生产巧克力、茶和时钟;2 月,它生产可乐和书籍。

class ProductBase
{
    protected ProductBase(string name, double price)
    {
        Name = name;
        Price = price;
    }

    public int Type { get; protected set; }

    public string Name { get; private set; }

    public double Price { get; private set; }
}

class Food : ProductBase
{
    protected Food(string name, double price)
        : base(name,price)
    { Type = 1; }

    public bool IsFried { get; set; }
}

class Drink : ProductBase
{
    protected Drink(string name, double price)
        : base(name,price)
    { Type = 2; }

    public bool IsLowFat { get; set; }
}

class Other : ProductBase
{
    protected Other(string name, double price)
        : base(name,price)
    { Type = 3; }
}

现在我需要展示产品。为方便起见,食物应始终放在第一个位置,饮料放在第二个位置,其他位置放在第三个位置。另外,即使没有食品,它的地方也不能容纳饮料或其他产品。

这是所有三种产品。LF 表示绿茶是低脂的。 3 个产品

如果只有两种产品,它应该像这样呈现。 2 个产品

每条线应具有相同的宽度和高度。IsLowFat/IsFried 位于第一列,名称位于第二列,价格位于第三列。第二列的宽度可以改变,以适应容器的可用宽度。

在上面的演示中,我使用了这段代码,但它非常难看,并且FontSize 无法根据窗口大小发光。我试过 ViewBox 但我无法处理它。

<Window x:Class="WpfApplication1.Window1"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="Window1" Height="190" Width="402" FontSize="30">
    <UniformGrid Rows="3" >
        <DockPanel>
            <TextBlock Width="50"  Text="" Margin="0,0,5,0" DockPanel.Dock="Left" />
            <TextBlock DockPanel.Dock="Right" Text=""/>
            <TextBlock TextAlignment="Left" Text=""/>
        </DockPanel>
        <DockPanel>
            <TextBlock Width="50" Text="LF" Margin="0,0,5,0" DockPanel.Dock="Left" />
            <TextBlock DockPanel.Dock="Right" Text="$2"/>
            <TextBlock TextAlignment="Left" Text="Green Tea"/>
        </DockPanel>
        <DockPanel>
            <TextBlock  Width="50" Text="" Margin="0,0,5,0" DockPanel.Dock="Left" />
            <TextBlock DockPanel.Dock="Right" Text="$7"/>
            <TextBlock TextAlignment="Left" Text="Beautiful Clock"/>
        </DockPanel>
    </UniformGrid>
</Window>

那么你的建议是什么?满足我要求的最佳方式是什么?任何见解都值得赞赏。

4

0 回答 0