or
I have a ListBox bound to collection of items, which each defines its Command in the ViewModel.
The SelectedItem is Bound to the ViewModel of the ListBox itself with TwoWay-Binding since I need to change Selection from Code.
Short version looks like this.
<telerik:RadListBox ItemsSource="{Binding Items}"
ItemTemplate="{StaticResource ItemTemplate}"
SelectedItem="{Binding SelectedItem, Mode=TwoWay}"
Command="{Binding SelectedItem.Command}"
SelectionMode="Single">
Now I've encountered the problem, that if I set SelectedItem in the ViewModel to 'null', the Item thats just been DeSelected still fires its Command one more time, which I personally would consider a bug.
Also this leads to an interesting behaviour in my app...
Someone any ideas, other than to create an event Handler for Selection changed and fire the Command from CodeBehind?
Any suggestions would be much appreciated.
Thx a bunch.
<Window xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation" x:Class="MainWindow" xmlns:Forms32="clr-namespace:System.Windows.Forms;assembly=System.Windows.Forms" Title="MainWindow" Height="350" Width="525"> <Grid> <telerik:RadDropDownButton Content="Browser" HorizontalAlignment="Left" Height="Auto" IsOpen="False" Margin="36,21,0,0" VerticalAlignment="Top" Width="Auto" DropDownWidth="800" DropDownHeight="600"> <telerik:RadDropDownButton.DropDownContent> <WindowsFormsHost> <Forms32:WebBrowser Url="google.com"></Forms32:WebBrowser> </WindowsFormsHost> </telerik:RadDropDownButton.DropDownContent> </telerik:RadDropDownButton> <telerik:RadDropDownButton Content="Button" HorizontalAlignment="Left" Height="Auto" IsOpen="False" Margin="129,21,0,0" VerticalAlignment="Top" Width="Auto"> <telerik:RadDropDownButton.DropDownContent> <WindowsFormsHost> <Forms32:TextBox Text="Test Text Box"></Forms32:TextBox> </WindowsFormsHost> </telerik:RadDropDownButton.DropDownContent> </telerik:RadDropDownButton> </Grid></Window>
<telerik:RadGridView> <telerik:RadGridView.ControlPanelItems> <telerik:ControlPanelItem ButtonTooltip="{x:Static res:ColumnChooserTooltip}"> <telerik:ControlPanelItem.Content> <ListBox ItemsSource="{Binding Columns}" Style="{StaticResource ColumnChooserListBox}"> <ListBox.ItemTemplate> <DataTemplate> <CheckBox Content="{Binding Header, Mode=OneWay}" IsChecked="{Binding IsVisible, Mode=TwoWay}" Style="{StaticResource ListItemsCheckBox}" /> </DataTemplate> </ListBox.ItemTemplate> </ListBox> </telerik:ControlPanelItem.Content> </telerik:ControlPanelItem> </telerik:RadGridView.ControlPanelItems> <telerik:RadGridView.Columns> <telerik:GridViewDataColumn Header="{x:Static res:Column1Name}" /> <telerik:GridViewDataColumn Header="{x:Static res:Column2Name}" /> <telerik:GridViewDataColumn Header="{x:Static res:Column3Name}" /> ... </telerik:RadGridView.Columns></telerik:RadGridView><telerik:RadGridView.Resources> <CollectionViewSource Source="{Binding Columns}" x:Key="AlphabetizedColumnsSource"> <CollectionViewSource.SortDescriptions> <scm:SortDescription PropertyName="Header"/> </CollectionViewSource.SortDescriptions> </CollectionViewSource></telerik:RadGridView.Resources><telerik:RadGridView.ControlPanelItems> <telerik:ControlPanelItem ButtonTooltip="{x:Static res:ColumnChooserTooltip}"> <telerik:ControlPanelItem.Content> <ListBox ItemsSource="{Binding Source={StaticResource AlphabetizedColumnsSource}}" Style="{StaticResource ColumnChooserListBox}"> <ListBox.ItemTemplate> <DataTemplate> <CheckBox Content="{Binding Header, Mode=OneWay}" IsChecked="{Binding IsVisible, Mode=TwoWay}" Style="{StaticResource ListItemsCheckBox}" /> </DataTemplate> </ListBox.ItemTemplate> </ListBox> </telerik:ControlPanelItem.Content> </telerik:ControlPanelItem></telerik:RadGridView.ControlPanelItems>

