這是XAML:
<controls:SplitButton x:Name="splitButton"
SelectedIndex="1"
HorizontalAlignment="Left"
VerticalAlignment="Top"
Grid.Column="1">
<controls:SplitButton.ItemTemplate>
<DataTemplate>
<Grid>
<TextBlock HorizontalAlignment="Left"
TextWrapping="Wrap"
Text="{Binding Text}"
VerticalAlignment="Top"/>
</Grid>
</DataTemplate>
</controls:SplitButton.ItemTemplate>
</controls:SplitButton>
這是後面的代碼:
class SplitButtonItem
{
public string Text { get; set; }
}
public MainWindow()
{
InitializeComponent();
var button1 = new SplitButtonItem() { Text = "Item 01", };
var button2 = new SplitButtonItem() { Text = "Item 02", };
var buttonList = new List<SplitButtonItem>()
{
button1,
button2,
};
splitButton.ItemsSource = buttonList;
}
這是怎麼看待運行:
這就是你正在找?