0

I'm using wpf mahapps theme and I want to create items for a SplitButton like so:

<Controls:SplitButton HorizontalAlignment="Left" Margin="26,581,0,0" VerticalAlignment="Top" SelectedIndex="1" IsExpanded="True" Background="White">
  <Controls:SplitButton.Items>
          <Button Content="btn" Background="#FFB23E3E"/>
          <MenuItem Background="#FF742323"/>
          <ComboBoxItem Content="cbx" Background="#FFA43131"/>
          <CheckBox Background="#FF8D3535" Content="chk"/>
  </Controls:SplitButton.Items>
</Controls:SplitButton>

but when I click on it, nothing happened and I don't know what's wrong ?

enter image description here

Fish
  • 165
  • 3
  • 16

1 Answers1

1

Try This,

<controls:SplitButton ItemsSource="{Binding}" >
    <controls:SplitButton.ItemTemplate>
        <DataTemplate>
            <Grid>
              <StackPanel>
                <Button Content="btn" Background="#FFB23E3E"/>
                <MenuItem Background="#FF742323"/>
                <ComboBoxItem Content="cbx" Background="#FFA43131"/>
                <CheckBox Background="#FF8D3535" Content="chk"/>
              </StackPanel>
            </Grid>
        </DataTemplate>
    </controls:SplitButton.ItemTemplate>
</controls:SplitButton>

You have to specify ItemSource to populate your ItemTemplate

Abin
  • 2,868
  • 1
  • 23
  • 59
  • I don't want to bind to ItemSource. – Fish Oct 01 '15 at 14:25
  • Edited the answer check if its helpful. – Abin Oct 01 '15 at 14:36
  • my desire is when I click the SplitButton, it'll show its items like a combobox so I can select an item. Your solution display all items like a stackpanel and it's not what I really want :( – Fish Oct 01 '15 at 14:46
  • Yes you can do that [Check This too](http://stackoverflow.com/a/27340082/2470362) – Abin Oct 01 '15 at 14:47