如何从ViewModel WPF向画布添加省略号

时间:2016-12-04 19:49:49

标签: c# wpf xaml canvas mvvm

我使用MVVM制作Mill游戏。我想从ViewModel向画布添加省略号。我已经制作了一个xaml代码,但它不起作用,它不会显示任何内容。你能帮我解决下面的代码吗?谢谢!

<Window x:Class="Malom.View.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:Malom"
    mc:Ignorable="d"
    Title="Malom Game" Height="530" Width="500">


<ItemsControl ItemsSource="{Binding Fields}">
    <ItemsControl.ItemsPanel>
        <ItemsPanelTemplate>
            <Canvas Margin="0,30,0,0" IsItemsHost="True"/>
        </ItemsPanelTemplate>
    </ItemsControl.ItemsPanel>

    <ItemsControl.ItemContainerStyle>
        <Style TargetType="ContentPresenter">
            <Setter Property="Canvas.Left" Value="{Binding _x}"></Setter>
            <Setter Property="Canvas.Top" Value="{Binding _y}"></Setter>
        </Style>
    </ItemsControl.ItemContainerStyle>
    <ItemsControl.ItemTemplate>
        <DataTemplate>
            <Ellipse Width="35" Height="35">
                <Ellipse.Style>
                    <Style TargetType="Ellipse">
                        <Style.Triggers>
                            <DataTrigger Binding="{Binding _color}" Value= "Fields.Empty">
                                <Setter Property="Fill" Value="Black"/>
                            </DataTrigger>
                            <DataTrigger Binding="{Binding _color}" Value= "Fields.BluePlayer">
                                <Setter Property="Fill" Value="Blue"/>
                            </DataTrigger>
                            <DataTrigger Binding="{Binding _color}" Value= "Fields.RedPlayer">
                                <Setter Property="Fill"  Value="Red"/>
                            </DataTrigger>
                        </Style.Triggers>
                    </Style>
                </Ellipse.Style>
            </Ellipse>
        </DataTemplate>
    </ItemsControl.ItemTemplate>
</ItemsControl>

0 个答案:

没有答案