or
I am using WPF
having a strange issue with RadListBox
SelectedItem databinding, trying to figure out but no luck. Following is my scenario
Telerik
Controls (RadListBox
, and RadButton
)RadButton
is placed inside a ItemsControl
, RadListBox
and ItemsControl
are bind to sameItemsSource
.PRISM
and MVVM
.RadListBox
automatically,(This part working fine).RadListBox
and then click back on any button the item selection stops working.RadListBox
?Now let me come to code.
ViewModel Class
public class MainViewModel : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
// Create the OnPropertyChanged method to raise the event
protected void OnPropertyChanged(string name)
{
PropertyChangedEventHandler handler = PropertyChanged;
if (handler != null)
{
handler(this, new PropertyChangedEventArgs(name));
}
}
public DelegateCommand<
object
> StudentSelected { get; set; }
public DelegateCommand<
object
> ButtonPressed { get; set; }
private void OnStudentSelected(object par)
{
//Debugger.Break();
if (handled == false)
{
Student std = par as Student;
if (std != null)
{
SelectedStudent = std;
}
}
handled = false;
}
private void OnButtonPressed(object par)
{
//Debugger.Break();
handled = true;
String std = par as String;
if (std != null)
{
foreach (Student st in _students)
{
if (st.Name.Equals(std))
{
SelectedStudent = st;
break;
}
}
}
}
private Student _selectedstudent;
private bool handled = false;
public MainViewModel()
{
StudentSelected = new DelegateCommand<
object
>(OnStudentSelected);
ButtonPressed = new DelegateCommand<
object
>(OnButtonPressed);
}
public Student SelectedStudent
{
get
{
return _selectedstudent;
}
set
{
_selectedstudent = value;
OnPropertyChanged("SelectedStudent");
}
}
private ObservableCollection<
Student
> _students;
public ObservableCollection<
Student
> Students
{
get
{
return _students;
}
set
{
_students = value;
OnPropertyChanged("Students");
}
}
}
public class Student
{
public String Name { get; set; }
public String School { get; set; }
}
<
telerik:RadListBox
Grid.Column
=
"0"
Grid.Row
=
"0"
ItemsSource
=
"{Binding Students}"
Command
=
"{Binding StudentSelected}"
CommandParameter
=
"{Binding RelativeSource={RelativeSource Mode=Self}, Path=SelectedItem}"
SelectedItem
=
"{Binding SelectedStudent, Converter={StaticResource DebugConverter}}"
>
<!-- The above debug converter is just for testing binding, as long as I keep on clicking button the Converter is being called, but the moment I click on RadListBoxItem the Converter is not called anymore, even when I click back on buttons -->
<
telerik:RadListBox.ItemTemplate
>
<
DataTemplate
>
<
TextBlock
Text
=
"{Binding Name}"
></
TextBlock
>
</
DataTemplate
>
</
telerik:RadListBox.ItemTemplate
>
</
telerik:RadListBox
>
<
Label
Grid.Row
=
"0"
Grid.Column
=
"1"
Content
=
"{Binding SelectedStudent.Name}"
></
Label
>
<
StackPanel
Grid.Column
=
"1"
Grid.Row
=
"1"
Orientation
=
"Horizontal"
>
<
ItemsControl
ItemsSource
=
"{Binding Students}"
>
<
ItemsControl.ItemTemplate
>
<
DataTemplate
>
<
telerik:RadButton
Width
=
"100"
Height
=
"70"
Content
=
"{Binding Name}"
Command="{Binding RelativeSource={RelativeSource FindAncestor,
AncestorType={x:Type Window}},
Path
=
DataContext
.ButtonPressed}"
CommandParameter
=
"{Binding RelativeSource={RelativeSource Mode=Self}, Path=Content}"
>
</
telerik:RadButton
>
</
DataTemplate
>
</
ItemsControl.ItemTemplate
>
</
ItemsControl
>
</
StackPanel
>
MainViewModel mvm = new MainViewModel();
ObservableCollection<
Student
> students = new ObservableCollection<
Student
>();
students.Add(new Student { Name = "Student 1", School = "Student 1 School" });
students.Add(new Student { Name = "Student 2", School = "Student 2 School" });
students.Add(new Student { Name = "Student 3", School = "Student 3 School" });
mvm.Students = students;
//Bind datacontext
this.DataContext = mvm;
Hi,
I have an unexpected behavior with Docking control. To reproduce the issue, you can use the WPF Docking First Look example. Follow these steps:
You can use all of the docking examples to reproduce the issue.
The issue exist in Silverlight too.
Is there a way to avoid this?
Thanks,
Christophe
Private
_manualPointMarkFill
As
Brush
Private
_manualSelectedPointMark
As
PointMark
Private
Sub
SetPointMarkSelectedState()
_manualPointMarkFill = _manualSelectedPointMark.Fill
_manualSelectedPointMark.Fill =
New
SolidColorBrush(Colors.Black)
End
Sub
Private
Sub
ClearPointMarkSelectedState()
If
_manualSelectedPointMark IsNot
Nothing
Then
'The Color of the PointMark do not reset to white, the PointMark remains black.
_manualSelectedPointMark.Fill = _manualPointMarkFill
'That works, but is only correct if the PointMark was white before.
'_manualSelectedPointMark.Fill = Brushes.White
_manualSelectedPointMark =
Nothing
End
If
End
Sub