Mahapp SplitButton无法正常工作

时间:2014-12-20 15:12:23

标签: wpf mahapps.metro

在Mahapp的文档中,SplitButton使用binding来获取其数据源。但我只是想手动添加SplitButton的数据。

<controls:SplitButton Grid.Row="3"
    HorizontalContentAlignment="Left"
    HorizontalAlignment="Center"
    VerticalContentAlignment="Center"
    Width="120"
    DisplayMemberPath="Title"
    VerticalAlignment="Top">
            <controls:SplitButton.Items>
                <Label>1</Label>
                <Label>2</Label>
            </controls:SplitButton.Items>
</controls:SplitButton>

但是,我无法看到弹出窗口。有什么想法吗?

enter image description here

2 个答案:

答案 0 :(得分:2)

您应该使用ItemsSource和可枚举,不要指定DisplayMemberPath

<controls:SplitButton HorizontalContentAlignment="Left"
                        HorizontalAlignment="Center"
                        VerticalContentAlignment="Center"
                        Width="120"
                        VerticalAlignment="Top">
    <controls:SplitButton.ItemsSource>
        <x:Array Type="system:String">
            <system:String>Label 1</system:String>
            <system:String>Another one</system:String>
            <system:String>Works now</system:String>
        </x:Array>
    </controls:SplitButton.ItemsSource>
</controls:SplitButton>

enter image description here

希望有效。

答案 1 :(得分:0)

那是因为您定义了两次商品来源:

ItemsSource="{Binding}"

 <controls:SplitButton.Items>
     <Label>1</Label>
     <Label>2</Label>
 </controls:SplitButton.Items>

只需删除ItemsSource属性。

<controls:SplitButton Grid.Row="3"
    HorizontalContentAlignment="Left"
    HorizontalAlignment="Center"
    VerticalContentAlignment="Center"
    Width="120"
    VerticalAlignment="Top">
        <controls:SplitButton.Items>
            <Label>1</Label>
            <Label>2</Label>
        </controls:SplitButton.Items>
</controls:SplitButton>