This is a migrated thread and some comments may be shown as answers.

RadPanelBar Selected Event

1 Answer 167 Views
PanelBar
This is a migrated thread and some comments may be shown as answers.
Mike Ro
Top achievements
Rank 2
Mike Ro asked on 30 May 2010, 03:50 AM
Hi.

I have a problem with setting up Selected event for RadPanelBar.
My aim is to catch an event when RadPanelBarItem is selected.

I am using DataTemplate for Item, and EntityObject entityObject containing a List<Employee>

XAML:
Resources:
<Window.Resources>   
 
<DataTemplate x:Key="RadPanelBarItemTemplate">   
 
<StackPanel MouseLeftButtonDown="pnlEmployee_MouseLeftButtonDown" Background="Transparent" Name="pnlEmployee" Orientation="Horizontal" VerticalAlignment="Stretch" HorizontalAlignment="Stretch">   
 
<Image Source="{Binding Photo}" Stretch="Uniform" HorizontalAlignment="Left" VerticalAlignment="Stretch" Width="50" Height="50"></Image> 
 
<Label Name="lblEmployeeName" Height="50" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Content="{Binding Name}" />   
 
<Label Name="lblEmployeeID" Content="{Binding Id}" Visibility="Hidden" />   
 
</StackPanel>   
 
</DataTemplate >   
 
</Window.Resources>   
 
 

 


RadPanelBar: 

 

<telerik:RadPanelBar Grid.Row="1" Name="rpbLeftMenu" ExpandMode="Single" Selected="rpbLeftMenu_Selected">   
 
<telerik:RadPanelBarItem Name="rpbiEmployee" IsExpanded="True" ItemsSource="{Binding Employees}" ItemTemplate="{StaticResource RadPanelBarItemTemplate}">   
 
<telerik:RadPanelBarItem.Header>   
 
<StackPanel HorizontalAlignment="Left">   
 
<Label Name="lblEmployees" Content="Сотрудники"></Label>   
 
<TextBox HorizontalAlignment="Left" Name="txtEmployeesFilter" TextChanged="txtEmployeesFilter_TextChanged" Width="200"></TextBox>   
 
</StackPanel>   
 
</telerik:RadPanelBarItem.Header>   
 
</telerik:RadPanelBarItem> 
 
...  
 
</telerik:RadPanelBar>   
 

 

 

CodeBehind:

Getting data from DB:

try 
 
{   
 
IMSSDataClassesDataContext db = new IMSSDataClassesDataContext();   
 
var query = from employees in db.imss_employees   
            orderby employees.emp_lastname   
            select new { employees.emp_ID };   
 
foreach (var emp in query)   
{  
var em = db.get_employee_name_by_id(emp.emp_ID).First();   
entityObject.Employees.Add(  
new Employee(em.name, emp.emp_ID, ShowEmpImage(emp.emp_ID)));   
}  
 
rpbLeftMenu.DataContext = entityObject;  
 
}  
catch (Exception ex)   
{  
...  
}  
 


My solution for selecting Item event is to handle a StackPanel MouseLeftButtonDown event:

 

private void pnlEmployee_MouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e)   
{  
StackPanel sp = sender as StackPanel;   
Label lb = sp.FindName("lblEmployeeID"as Label;   
this.Title = Convert.ToString(lb.Content); //just for testing purposes   
}  
 
 

But it works only when clicking correctly inside a stackpanel.

I want something like this:

  

<telerik:RadPanelBarItem Selected="RadPanelBarItem_Selected">   
<telerik:RadPanelBarItem.Header>   
<StackPanel Orientation="Horizontal" Margin="5">   
<TextBlock Text="BMW 128i Coupe" Margin="15 10 0 0" />   
</StackPanel>   
</telerik:RadPanelBarItem.Header>   
</telerik:RadPanelBarItem>   
   
private void RadPanelBarItem_Selected(object sender, Telerik.Windows.RadRoutedEventArgs e)   
{  
...  
}  
 

 

 

 

But I can't set Selected event handler for Items which are binded like mine:
ItemsSource="{Binding Employees}" 

How should I catch selection of Items?

Best regards,

1 Answer, 1 is accepted

Sort by
0
Mike Ro
Top achievements
Rank 2
answered on 31 May 2010, 03:17 AM
Finally, I have found solution:

 

private void rpbiEmployee_Selected(object sender, Telerik.Windows.RadRoutedEventArgs e)  
        {  
            RadPanelBarItem rpbi = e.Source as RadPanelBarItem;  
            RadPanelBar cd = rpbi.Parent as RadPanelBar;  
 
            Employee sel_emp = cd.SelectedItem as Employee;  
            if (sel_emp != null)  
            {  
                Title = sel_emp.Name;  
            }  
        } 

 

 

 

 

 

Tags
PanelBar
Asked by
Mike Ro
Top achievements
Rank 2
Answers by
Mike Ro
Top achievements
Rank 2
Share this question
or