Selected Item not displayed

5 posts, 0 answers
  1. Chris
    Chris  avatar
    42 posts
    Member since:
    Apr 2009

    Posted 29 Apr 2011 Link to this post

    When displaying "Name" from button collection, selected item is not displayed.
    It looks pretty straight forward but I can't think of why it won't work.. hmm..
    Is this a telerik bug?
    The following code shows two different methods, "DataTemplate" and "DisplayMemberPath"
    I appreciate for your help.
    -chris


    <Window x:Class="RadComboBoxExample.MainWindow"
            Title="MainWindow" Height="350" Width="525">
        <Grid x:Name="grid">
            <Grid.Resources>
                <DataTemplate x:Key="comboTemplate">
                    <TextBlock Text="{Binding Name}" />
                </DataTemplate>
            </Grid.Resources>
            <Grid.ColumnDefinitions>
                <ColumnDefinition />
                <ColumnDefinition />
            </Grid.ColumnDefinitions>
              
            <StackPanel Grid.Column="0" Orientation="Vertical">
                <TextBlock Text="Use ItemTemplate" Margin="10" FontSize="15" HorizontalAlignment="Center" />
                <telerik:RadComboBox x:Name="comboBox1" Width="100" Height="30"  
                                     ItemsSource="{Binding ButtonCollection1}" 
                                     SelectedItem="{Binding SelectedButton1}" 
                                     ItemTemplate="{StaticResource comboTemplate}"/>
            </StackPanel>
      
            <StackPanel Grid.Column="1" Orientation="Vertical">
                <TextBlock Text="Use DisplayMemberPath" Margin="10" FontSize="15" HorizontalAlignment="Center" />
                <telerik:RadComboBox x:Name="comboBox2" Width="100" Height="30" 
                                     Grid.Column="1"
                                     ItemsSource="{Binding ButtonCollection2}" 
                                     SelectedItem="{Binding SelectedButton2}" 
                                     DisplayMemberPath="Name"/>
            </StackPanel>
        </Grid>
    </Window>

    using System.Collections.ObjectModel;
    using System.Windows;
    using Telerik.Windows.Controls;
      
    namespace RadComboBoxExample
    {
        public partial class MainWindow : Window
        {
            public ObservableCollection<RadButton> ButtonCollection1 { get; set; }
            public ObservableCollection<RadButton> ButtonCollection2 { get; set; }
            public RadButton SelectedButton1 { get; set; }
            public RadButton SelectedButton2 { get; set; }
      
            public MainWindow()
            {
                InitializeComponent();
      
                ButtonCollection1 = new ObservableCollection<RadButton>();
                ButtonCollection2 = new ObservableCollection<RadButton>();
      
                for (int i = 0; i < 10; i++)
                {
                    RadButton button1 = new RadButton();
                    button1.Name = "Button1_Item" + i;
                    ButtonCollection1.Add(button1);
      
                    RadButton button2 = new RadButton();
                    button2.Name = "Button2_Item" + i;
                    ButtonCollection2.Add(button2);
                }
      
                grid.DataContext = this;
            }
        }
    }

  2. Yana
    Admin
    Yana avatar
    4554 posts

    Posted 04 May 2011 Link to this post

    Hello Chris,

    It's not recommended to load UI elements in the view model. Please replace RadButton with a custom object in order to fix this issue. I've attached a simple example to demonstrate the approach.

    Kind regards,
    Yana
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. UI for WPF is Visual Studio 2017 Ready
  4. Chris
    Chris  avatar
    42 posts
    Member since:
    Apr 2009

    Posted 04 May 2011 Link to this post

    Thanks Yana,
    I was aware of non-ui-element works as in your sample.
    But I wasn't quite sure why it doesn't work for ui-element types, such as Button?
    There is a reason why I'm using a button.
    I would like to know at least why it doens't support. It doesn't seem logical to me.  hmm..

    Thanks.

    -chris
  5. Yana
    Admin
    Yana avatar
    4554 posts

    Posted 06 May 2011 Link to this post

    Hello Chris,

    I'm sorry for not explaining.

    We follow the behavior of standard ComboBox.  If you replace RadComboBox with ComboBox in your example, you'll observe the same result.  I suggest to place the button in the ItemTemplate of the combobox. You can also set SelectionBoxTemplate as explained here.

    Greetings,
    Yana
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  6. Chris
    Chris  avatar
    42 posts
    Member since:
    Apr 2009

    Posted 06 May 2011 Link to this post

    Thanks for trying to help
    You are right, normal wpf behavior is the same but that still doesn't explain why it shouldn't work.
    It looks more like a bug than a feature. ^^

    Regards,

    -chris
Back to Top
UI for WPF is Visual Studio 2017 Ready