It will be handy for others also. I am giving my solution here. This will help to make buttons dynamically in a ItemsControl or ListBox.
After some working hard i was able to do it as i wanted.
in my XAML i did like this.
<itemscontrol x:name="ic"><br />
<itemscontrol.itemtemplate><br />
<datatemplate><br />
<Button<br />
Command="Open"<br />
CommandParameter="{Binding Path=ID}"<br />
Cursor="Hand"<br />
Focusable="False"<br />
><br />
<Button.Template><br />
<controltemplate targettype="Button"><br />
<border><br />
removed="Black"<br />
BorderBrush="#88000000"<br />
BorderThickness="0.5"<br />
Padding="1"<br />
><br />
<dockpanel><br />
<Button<br />
Background="Transparent" <br />
Command="{Binding Open}"<br />
CommandParameter="{Binding Path=ID}"<br />
Content="{Binding Path=Content}"<br />
DockPanel.Dock="Top"<br />
Focusable="False"<br />
Foreground="White"<br />
HorizontalAlignment="Stretch"<br />
Margin="0"<br />
ToolTip="Testing Buttons..."<br />
Click="Button_Click"<br />
/><br />
<dockpanel.commandbindings><br />
<commandbinding command="Open" executed="Open_Executed" /><br />
</dockpanel.commandbindings><br />
</dockpanel><br />
</border><br />
</controltemplate><br />
</Button.Template><br />
</Button><br />
</datatemplate><br />
</itemscontrol.itemtemplate><br />
</itemscontrol>
then code behind i did like the following:
buttonContentList = MainButtonsList.FindAll(o => (o.MenuLevel == levelID) && (o.GroupID == groupID) && (o.Enable == isEnable));<br />
this.ic.Items.Clear();<br />
int buttonIndex = 0;<br />
foreach (ButtonContent bc in buttonContentList)<br />
{<br />
Button btn = new Button();<br />
btn.Click += new RoutedEventHandler(btn_Click);<br />
btn.Content = bc.Content;<br />
btn.Tag = buttonIndex++;<br />
btn.Height = 60;<br />
btn.Width = 80;<br />
btn.Margin = new Thickness(10, 5, 0, 5);<br />
<br />
this.ic.Items.Add(btn);<br />
}