在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>
但是,我无法看到弹出窗口。有什么想法吗?
答案 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>
希望有效。
答案 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>